quiz 3 Flashcards

1
Q

What is the output of the final print() after the following statements?

x = ‘abcdefgh’
print(x[::-1][2:5])

A

fed

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What will be y after the following statement?

x = ‘Monday’
y = x[0:4][100:500] + x[3::2]

A

“dy”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What collection would you use to store data in terms of key and values?

A

dictionary

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What commands create a list?

A

x = list, y = [], z = list([1, 2, 3])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the output of the following?

x = [1, 2, 3]
y = x
print(id(x) == id(y))

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the output after the following?

for x in range(10, 20, 2):
print(x, end=” “)

A

10 12 14 16 18

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

It is impossible to change any immutable collection to a mutable one with the same elements.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How many numbers will be printed?

for i in (1 ,2 ,3):
for j in range(0, i):
print(i + j)

A

6

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

It is impossible to read an entire text file into a list of lines using one of the standard Python functions.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

The same syntax can be used for iterating over a list, tuple, string, set and dictionary.

A

True

How well did you know this?
1
Not at all
2
3
4
5
Perfectly