10000 added conditions.py for if, not, is and in operator demo · sdevikar/python@67361cf · GitHub
[go: up one dir, main page]

Skip to content

Commit 67361cf

Browse files
author
sdevikar
committed
added conditions.py for if, not, is and in operator demo
1 parent 6e5f9d1 commit 67361cf

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

python2/conditions.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# booleans
2+
x = 3
3+
print x == 2
4+
5+
# proper indentation in python is essential
6+
if x == 2:
7+
print "x is indeed 2"
8+
print "it's insane that the if block is determined by indentation"
9+
# print "this will give me an error"
10+
print "So, this will be printed regardless of x == 2"
11+
12+
# combining boolean expressions
13+
y = 5
14+
15+
if x == 2 and y == 5:
16+
print "Think positive"
17+
elif x == 3 and y == 5:
18+
print "Life's okay, I guess"
19+
else:
20+
print "That's it, I'm done!"
21+
22+
# iterating using in operator
23+
name = "SlimShady"
24+
rappers = ["SlimShady", "TheRealSlimShady", "Eminem"]
25+
26+
if name in rappers:
27+
print "He's from Detroit"
28+
else:
29+
print "He's not a real rapper"
30+
31+
# comparing values vs objects
32+
x = [1, 2, 3]
33+
y = [1, 2, 3]
34+
35+
if x == y:
36+
print "x and y are equal in terms of their values"
37+
38+
if x is y:
39+
print "x and y are the same object"
40+
else:
41+
print "they're different objects though"
42+
43+
# the not operator
44+
if True is not False:
45+
print "This concludes the chapter"
46+
print not False
47+
print not True

0 commit comments

Comments
 (0)
0