forked from Hesenius/SafariPython
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathequality.py
49 lines (41 loc) · 926 Bytes
/
equality.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
x = 99
y = 100
print(x == y) # bool literals True, False
print(x != y)
print(type(x == y))
x = "Hello"
y = "He"
# y = y + "llo"
y += "llo"
print(x, y)
print(x == y) # content-comparison equality, implemented __eq__
# many others __lt__ etc..
print(x != y)
print(x is y)
# "Recently" we got the "Walrus" operator
# Walrus assignment has value
print(f"x before is {x}")
print(x := 3)
print(f"x after is now {x}")
# < > <= >=
print(3 < 9)
# name = input("What is your name ")
# print("Hello", name)
# Not permitted, we're ignoring the value of the expression
# wal := 55
x = (wal := 55)
print(wal)
print(type(x))
# Not meaningful either, but evidently permitted
x + 2
x = "Hello"
y = "He"
y += "llo"
# y = "Hello"
print(x == y)
print(x is y)
# and, or are bool type operators xor is in a library!
# & | are bitwise operators (they work on bool)
print(x == "Hello" and len(x) > 3)
# bitwise xor is built in
print(3 ^ 6)