-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpython_operators.py
More file actions
103 lines (72 loc) · 1.89 KB
/
python_operators.py
File metadata and controls
103 lines (72 loc) · 1.89 KB
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
95
96
97
98
99
100
101
102
103
# Hello World program in Python
print("Example of Python Operators!\n")
print(" Python Arithmetic Operators\n")
x = 15
y = 3
print(x + y)
print(x - y)
print(x * y)
print(x / y)
print(x % y)
print(x ** y)
print(x // y)
print(" Python Assignment Operators\n")
x = 43
x += 3
print(x)
x -= 3
print(x)
x *= 3
print(x)
x /= 3
print(x)
x %= 3
print(x)
x **= 3
print(x)
x //= 3
print(x)
print(" Python Comparison Operators\n")
x = 5
y = 3
print(x == y)
print(x != y)
print(x > y)
print(x < y)
print(x >= y)
print(x <= y)
print(" Python Logical Operators\n")
x = 5
print(x > 3 and x < 10)
print(x > 3 or x < 4)
print(not (x > 3 and x < 10))
print(" Python Identity Operators\n")
x = ["apple", "banana"]
y = ["apple", "banana"]
z = x
# is
print(x is z)
# returns True because z is the same object as x
print(x is y)
# returns False because x is not the same object as y, even if they have thew same content
print(x == y)
# to demonstrate the difference betweeen "is" and "==": this comparison returns True because x is equal to y
# is not
print(x is not z)
# returns False because z is the same object as x
print(x is not y)
# returns True because x is not the same object as y, even if they have the same content
print(x != y)
# to demonstrate the difference betweeen "is not" and "<>": this comparison returns False because x is equal to y
print(x is not z)
# returns False because z is the same object as x
print(x is not y)
# returns True because x is not the same object as y, even if they have the same content
print(x != y)
# to demonstrate the difference betweeen "is not" and "<>": this comparison returns False because x is equal to y
print(" Python Membership Operators\n")
x = ["apple", "banana"]
print("banana" in x)
# returns True because a sequence with the value "banana" is in the list
print("pineapple" not in x)
# returns True because a sequence with the value "pineapple" is not in the list