1>>> s1 = {"a", "b", "c"}
2>>> s2 = {"d", "e", "f"}
3
4>>> # OR, |
5>>> s1 | s2
6{'a', 'b', 'c', 'd', 'e', 'f'}
7>>> s1 # `s1` is unchanged
8{'a', 'b', 'c'}
9
10>>> # In-place OR, |=
11>>> s1 |= s2
12>>> s1 # `s1` is reassigned
13{'a', 'b', 'c', 'd', 'e', 'f'}
14
1#The (!) is the not operator in Python, (!=) means not equal to.
2if 2!=10:
3 print("2 isn't equal to 10.")
4elif 2==10:
5 print("2 is equal to 10.")
6#Prints "2 isn't equal to 10." as 2 isn't equal to 10. Is it?
7
8#Note that "=" is used for declarations (assign a value to a variable or change the value of one) while "==" is usually used for checking.
9#Usually, "==" returns a boolean, but depends on the objects being checked if they're equal or not, that the result will be boolean.
10#For example, some NumPy objects when checked will return values other than boolean (other than True or False).
11
12#For example:
13
14a = 10
15print(a)
16
17#will return the int 10
18#Now,
19
20print(a==10)
21
22#will return a boolean, True as we have assigned the value of a as 10
23
24#Another example (to make it easier and to avoid confusion) would be where
25
26a = 10
27b = 10
28
29#and
30
31print(a==b)
32
33#will return a boolean, True as they're equal.
34
35
1Python uses and and or conditionals.
2
3i.e.
4
5if foo == 'abc' and bar == 'bac' or zoo == '123':
6 # do something
1x = 5
2y = 6
3
4d = 12 % 5 # d is 2
5z = x + y # z is 11
6w = x - y # w is -1
7q = 5 * 6 # q is 30
8u = 10 / x # u is 2.0
9p = 10 * 2.0 # p is 20.0
10t = x ** 3 # t is 125
11c = 28 // y # c is 5
1Arithmetic operators: Arithmetic operators are used to perform mathematical
2 operations like addition, subtraction, multiplication and division.
3