Provide your own examples of the following using Python lists. Create your own examples. Do not copy them from another source.
Nested lists
The “*” operator
List slices
The “+=” operator
A list filter
A list operation that is legal but does the "wrong" thing, not what the programmer expects
Provide the Python code and output for your program and all your examples.
Nested_lists = ['only first "floor"', ['second floor',['Third floor', 'here living cats'],
['Underground', 'Dinasaurs', ['I dont know where we are']]]]
print('Nested lists: ', Nested_lists)
print('')
my_property = ['house', 'car', 'money', 'computer']
print('Now I have ')
print(my_property)
print(' but then I make my startup it will be ')
print(my_property * 5)
print('')
print('But if my startup fold up I will have only')
print(my_property[1:3])
print('')
me = ['car', 'flat']
wife = ['nothing']
print('When me and my wife married, we combined our property')
me += wife
print(me)
print('')
cars = ['BMW', 'Mercedes', 'Skoda']
print(cars)
print('Here something need to remove')
cars[0] = cars[2]
cars[1] = cars[2]
print('Alright')
print(cars)
print('')
# For me strange was that
car = 'skoda'
my_car = 'skoda'
print(car is my_car)
cars = ['bmw', 'mercedes', 'skoda']
my_cars = ['bmw', 'mercedes', 'skoda']
Comments
Leave a comment