-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path07_conditions.py
More file actions
47 lines (38 loc) · 1016 Bytes
/
07_conditions.py
File metadata and controls
47 lines (38 loc) · 1016 Bytes
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
# booleans
x = 3
print x == 2
# proper indentation in python is essential
if x == 2:
print "x is indeed 2"
print "it's insane that the if block is determined by indentation"
# print "this will give me an error"
print "So, this will be printed regardless of x == 2"
# combining boolean expressions
y = 5
if x == 2 and y == 5:
print "Think positive"
elif x == 3 and y == 5:
print "Life's okay, I guess"
else:
print "That's it, I'm done!"
# iterating using in operator
name = "SlimShady"
rappers = ["SlimShady", "TheRealSlimShady", "Eminem"]
if name in rappers:
print "He's from Detroit"
else:
print "He's not a real rapper"
# comparing values vs objects
x = [1, 2, 3]
y = [1, 2, 3]
if x == y:
print "x and y are equal in terms of their values"
if x is y:
print "x and y are the same object"
else:
print "they're different objects though"
# the not operator
if True is not False:
print "This concludes the chapter"
print not False
print not True