In [ ]:
x = 10
In [1]:
7 // 3
Out[1]:
2
In [2]:
7 % 3
Out[2]:
1
In [9]:
s = 'Hello, \nHow are \tyou?'
print(s)
Hello, 
How are 	you?
In [10]:
s[0]
s[8]
Out[10]:
'H'
In [12]:
# slice
s[3:6]
Out[12]:
'lo,'
In [13]:
s[3:]
Out[13]:
'lo, \nHow are \tyou?'
In [14]:
s[:6]
Out[14]:
'Hello,'
In [17]:
s.find('asd')
Out[17]:
-1
In [18]:
s.split(',')
Out[18]:
['Hello', ' \nHow are \tyou?']
In [19]:
s.split()
Out[19]:
['Hello,', 'How', 'are', 'you?']
In [20]:
xs = [10,20,30,40]
In [21]:
xs[2]
Out[21]:
30
In [22]:
xs[1:3]
Out[22]:
[20, 30]
In [23]:
len(s)
Out[23]:
21
In [24]:
len(xs)
Out[24]:
4
In [26]:
# if statement
# 6 comparisons: <, >, ==, !=, <=, >=
a = 10
if a > 10:
    print('more than 10')
else:
    print('less than or equal to 10')
less than or equal to 10
In [28]:
a = 5
if a > 10:
    print('more than 10')
In [29]:
score = 79
if score >= 90:
    print('A')
elif score >= 80 and score < 90:
    print('B')
elif score >= 70 and score < 80:
    print('C')
elif score >= 60 and score < 70:
    print('D')
else:
    print('F')
C
In [30]:
# for-loop
xs = [10,20,30,40]
for x in xs:
    print(x)
10
20
30
40
In [31]:
xs = [10,20,30,40]

# accumulator pattern
sum = 0
for x in xs:
    sum = sum + x
print(sum)
100
In [32]:
xs = [10,20,30,40]

# accumulator pattern
sum = 1
for x in xs:
    sum = sum * x
print(sum)
240000
In [33]:
def name_of_month(month):
    s = ['January','February','March']
    return s[month-1]
In [36]:
name_of_month(2)
Out[36]:
'February'
In [1]:
print("Helo",end='')
print(' how')
Helo how
In [ ]: