In [1]:
print('Hello, world!')
In [2]:
3
Out[2]:
In [3]:
3 * 4 + 5
Out[3]:
In [4]:
3 / 5
Out[4]:
In [5]:
3 // 5
Out[5]:
In [6]:
7 % 5
Out[6]:
In [7]:
2 ** 3
Out[7]:
In [8]:
2 ^ 3
Out[8]:
In [9]:
2 << 4
Out[9]:
In [10]:
3.14
Out[10]:
In [11]:
True, False
Out[11]:
In [12]:
1 == 1
Out[12]:
In [13]:
1 != 1
Out[13]:
In [14]:
None
In [15]:
'hello'
Out[15]:
In [16]:
"hello"
Out[16]:
In [17]:
"hello's"
Out[17]:
In [18]:
3 + 4j
Out[18]:
In [19]:
[1,2,3,4]
Out[19]:
In [20]:
[1,'a', 'hello', 3.14, 4j]
Out[20]:
In [22]:
print('''This is
a triple
quoted string''')
In [23]:
set([1,1,2,2,3,4,3,4])
Out[23]:
In [24]:
{'tom': 23, 'anne': 34}
Out[24]:
In [25]:
(1,2,3)
Out[25]:
In [26]:
x = [1,2,3,4]
In [27]:
x
Out[27]:
In [28]:
x[0]
Out[28]:
In [29]:
x[-1]
Out[29]:
In [30]:
x[0:2]
Out[30]:
In [31]:
x[:2]
Out[31]:
In [32]:
x[1:]
Out[32]:
In [33]:
x[:]
Out[33]:
In [34]:
contacts = {'tom': 23, 'anne': 34}
In [36]:
contacts['anne']
Out[36]:
In [37]:
contacts.keys()
Out[37]:
In [38]:
contacts.values()
Out[38]:
In [40]:
names = list(contacts.keys())
In [41]:
names
Out[41]:
In [42]:
names[0][1:3]
Out[42]:
In [43]:
names['bob']
In [44]:
contacts['bob']
In [45]:
1/0
In [46]:
squares = []
for i in range(1, 10):
squares.append(i**2)
In [47]:
squares
Out[47]:
In [52]:
count = 0
while count < 10:
print(count)
if count % 3 == 0:
break
count += 1
In [54]:
x = 10
if x % 3 == 0:
print('divisible by 3')
elif x % 5 == 0:
print('Divisible by 5')
else:
print('something else')
In [57]:
help(range)
In [ ]: