Python Chap 3 - Strings, List, Maps
Python Chap 3 - Strings, List, Maps
single quotes
nums = 'What did the number %s say to the number %s? Nice
belt!!'
print(nums % ('A','B'))
spaces = ' ' * 25
print('%s 12 Butts Wynd' % spaces)
print('%s Twinklebottom Heath' % spaces)
print('%s West Snoring' % spaces)
print()
print()
print('Dear Sir')
print()
print('I wish to report that tiles are missing
from the')
print('outside toilet roof.')
print('I think it was bad wind the other night
that blew them away.')
print()
print('Regards')
print('Malcolm Dithering')
List
>>> wizard_list = ['spider legs', 'toe of frog', 'eye of newt',
'bat wing', 'slug butter', 'snake dandruff’]
>>> print(wizard_list)
['spider legs', 'toe of frog', 'eye of newt', 'bat wing', 'slug
butter', 'snake dandruff']
Print the third item
>>> print(wizard_list[2])
list1 = [1, 2, 3, 4]
list2 = [5, 6, 7, 8]
list3 = list1 + list2
>>> print(list3)
Adding Items to a List
>>> wizard_list.append('bear burp')
>>> print(wizard_list)
['spider legs', 'toe of frog', 'snail tongue', 'bat wing', 'slug
butter', 'snake dandruff', 'bear burp']