True
True
False
False
True and False
False
True or False
True
not True
False
x = 24
x > 50 # six different comparisons: >, >=, ==, <, <=, !=
x != 30
True
24
24
2.35
2.35
24 + 36
60
2.35 * 3
7.050000000000001
41/2
20.5
41//2
20
41%2
1
"34 Main Street"
'34 Main Street'
'34 Main Street'
'34 Main Street'
'''abc
def
'''
'abc \ndef\n'
len("34 Main Street")
14
x = 24
y = len("34 Main Street")
print(x,y)
y = 36
print(x,y)
24 14 24 36
s = "abracadabra"
print(s)
# slice operation
x1 = s[4:7]
print(x1)
t = "hello"
# concatenation
u = s + t
print(u)
# find
i = s.find("xad") # finds the first occurrence of "cad" in s
print(i)
abracadabra cad abracadabrahello -1
s = "This is a long sentence in English long"
s.find("long")
10
x = 100
# if-statement
if x > 50:
print("x is more than 50")
print("I am done")
x is more than 50 I am done
x = 10
if x > 50:
print("x is more than 50")
print("I am done")
I am done
x = 10
# if-else statement
if x > 50:
print("x is more than 50")
print("haha")
else:
print("x is not more than 50")
print("I am done")
x is not more than 50 I am done
score = 85
# if-elif-else statement
if score >= 90:
print("A")
elif score >= 80 and score < 90:
print("B")
elif score >= 70:
print("C")
elif score >= 60:
print("D")
else:
print("F")
B
# 0 1 2 3 4 5
xs = [10,20,30,40,50,60]
ys = [90,100]
print(xs)
print(len(xs))
print(xs[2:4])
print(xs+ys)
print(xs.index(40))
print("abracadabra".index("cad"))
print(xs[3])
[10, 20, 30, 40, 50, 60] 6 [30, 40] [10, 20, 30, 40, 50, 60, 90, 100] 3 4 40
## list modifications
xs = [10,20,30,40,50]
print(xs)
xs.append(70)
print(xs)
xs.insert(1,90)
print(xs)
xs.remove(90)
print(xs)
[10, 20, 30, 40, 50] [10, 20, 30, 40, 50, 70] [10, 90, 20, 30, 40, 50, 70] [10, 20, 30, 40, 50, 70]
two main differences:
xs = ("John",24,"CSC")
print(xs[1:3])
(24, 'CSC')
for x in [10,20,30,40]:
print(x)
print(2*x)
10 20 20 40 30 60 40 80
n = 9
for x in [1,2,3,4,5,6,7,8,9,10]:
print(n,"*",x,"=",n*x)
9 * 1 = 9 9 * 2 = 18 9 * 3 = 27 9 * 4 = 36 9 * 5 = 45 9 * 6 = 54 9 * 7 = 63 9 * 8 = 72 9 * 9 = 81 9 * 10 = 90
n = 9
for x in range(1,20):
print(n,"*",x,"=",n*x)
9 * 1 = 9 9 * 2 = 18 9 * 3 = 27 9 * 4 = 36 9 * 5 = 45 9 * 6 = 54 9 * 7 = 63 9 * 8 = 72 9 * 9 = 81 9 * 10 = 90 9 * 11 = 99 9 * 12 = 108 9 * 13 = 117 9 * 14 = 126 9 * 15 = 135 9 * 16 = 144 9 * 17 = 153 9 * 18 = 162 9 * 19 = 171
x = input("Enter Earlier Time: ")
print(x)
44