1 With the following Python code
>>> "Hello" + 'World' + """!"""
the following applies:
2 The following Python code
>>> [1, 2, 'stock', 4]
constructs a
3 The following Python code
>>> colors = ('red', 'yellow', 'blue', 'black')
is a
4 The following Python code
>>> {'stock': 'NVO', 'wikipedia': 'Novo_Nordisk'}
5 The following Python code
>>> a = [[4, 5], [6, 7], [8, 9]]
may result in
<type 'list'>
6 The following Python code
>>> c = {'stock': 'NVO', 'wikipedia': 'Novo_Nordisk'}
c.keys()
c.items()
c.values()
['wikipedia', 'stock']
['Novo_Nordisk', 'NVO']
[('wikipedia', 'Novo_Nordisk'), ('stock', 'NVO')]
{'stock', 'wikipedia'}
7 The following Python code
>>> a = range(5) >>> b = a >>> a[3] = 77
results in
b = [0, 1, 2, 3, 4]
b = [1, 2, 3, 4, 5]
b = [0, 1, 2, 3, 4, 5]
b = [0, 1, 2, 77, 4]
b = [1, 2, 3, 77, 5]
b = [0, 1, 2, 77, 4, 5]
b = [0, 1, 77, 3, 4]
b = [1, 2, 77, 4, 5]
b = [0, 1, 77, 3, 4, 5]
8 The following Python code
>>> 'Result: ' + 23
9 To append a string and an integer
'Result: ' + 23
'Result: ' + str(23)
'Result: %d' % 23
sprintf('Result: %d', 23)
'Result: {result}'.format(**{'result': 23})
10 Consider the following data structure definition:
>>> names = {1: 'Anders', 2: "Bente", 3: "Charles"}
names[2]
names{2}
for name in names: print(name)
for key, value in names: print(value)
for key, value in names.items(): print(value)