quiz 3 Flashcards
What is the output of the final print() after the following statements?
x = ‘abcdefgh’
print(x[::-1][2:5])
fed
What will be y after the following statement?
x = ‘Monday’
y = x[0:4][100:500] + x[3::2]
“dy”
What collection would you use to store data in terms of key and values?
dictionary
What commands create a list?
x = list, y = [], z = list([1, 2, 3])
What is the output of the following?
x = [1, 2, 3]
y = x
print(id(x) == id(y))
True
What is the output after the following?
for x in range(10, 20, 2):
print(x, end=” “)
10 12 14 16 18
It is impossible to change any immutable collection to a mutable one with the same elements.
False
How many numbers will be printed?
for i in (1 ,2 ,3):
for j in range(0, i):
print(i + j)
6
It is impossible to read an entire text file into a list of lines using one of the standard Python functions.
False
The same syntax can be used for iterating over a list, tuple, string, set and dictionary.
True