Compare Operators
x == y
: value
x is y
: value and memory
1
2
3
4
| a = [1, 2, 3, 4, 5]
b = [1, 2, 3, 4, 5]
print(a == b)
print(a is b)
|
True
False
[Important] There’s reserved memory space -5 ~ 256 (shared memory)
1
2
3
4
| a = 256
b = 256
print(a == b)
print(a is b)
|
True
True
1
2
3
4
| a = 257
b = 257
print(a == b)
print(a is b)
|
True
False
True and False
int
: 1
True, else False
str
: ""
False, else True
all()
any()
1
2
3
| b = [True, False, True]
print(all(b)) # AND - True if everything is true
print(any(b)) # OR - True of any is true
|
False
True
for
for i in range(x,y,z)
: increment by z
from x
to y-1
1
2
3
4
5
| for i in range(2, 10, 2): # [2,10) +2
print(i, end="")
print("\n")
for i in range(11, 1, -2): # [11, 1) -2
print(i, end="")
|
2468
119753