-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
test_assigment.py
94 lines (72 loc) · 1.92 KB
/
test_assigment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"""Assignment operators
@see: https://www.w3schools.com/python/python_operators.asp
Assignment operators are used to assign values to variables
"""
def test_assignment_operator():
"""Assignment operator """
# Assignment: =
number = 5
assert number == 5
# Multiple assignment.
# The variables first_variable and second_variable simultaneously get the new values 0 and 1.
first_variable, second_variable = 0, 1
assert first_variable == 0
assert second_variable == 1
# You may even switch variable values using multiple assignment.
first_variable, second_variable = second_variable, first_variable
assert first_variable == 1
assert second_variable == 0
def test_augmented_assignment_operators():
"""Assignment operator combined with arithmetic and bitwise operators"""
# Assignment: +=
number = 5
number += 3
assert number == 8
# Assignment: -=
number = 5
number -= 3
assert number == 2
# Assignment: *=
number = 5
number *= 3
assert number == 15
# Assignment: /=
number = 8
number /= 4
assert number == 2
# Assignment: %=
number = 8
number %= 3
assert number == 2
# Assignment: %=
number = 5
number %= 3
assert number == 2
# Assignment: //=
number = 5
number //= 3
assert number == 1
# Assignment: **=
number = 5
number **= 3
assert number == 125
# Assignment: &=
number = 5 # 0b0101
number &= 3 # 0b0011
assert number == 1 # 0b0001
# Assignment: |=
number = 5 # 0b0101
number |= 3 # 0b0011
assert number == 7 # 0b0111
# Assignment: ^=
number = 5 # 0b0101
number ^= 3 # 0b0011
assert number == 6 # 0b0110
# Assignment: >>=
number = 5
number >>= 3
assert number == 0 # (((5 // 2) // 2) // 2)
# Assignment: <<=
number = 5
number <<= 3
assert number == 40 # 5 * 2 * 2 * 2