Show List
Quiz - Python - 2
Select the right answer for below questions:
What is the output of the following code:
x = [1, 2, 3, 4, 5]
print(len(x))
x = [1, 2, 3, 4, 5]
print(len(x))
5
4
3
2
5
What is the correct way to remove an element from a list in Python?
remove(element)
del element
pop(element)
list.remove(element)
list.remove(element)
What is the correct syntax for a while loop in Python?
while x < 5:
while (x < 5)
do while (x < 5)
repeat while x < 5
while x < 5:
What is the output of the following code:
x = 5
y = 6
print(x * y)
x = 5
y = 6
print(x * y)
11
10
30
36
36
What is the correct way to access a value from a dictionary in Python?
dict[key]
dict.key
dict.get(key)
dict.value(key)
dict[key]
What is the correct syntax for an if-else statement in Python?
if x == 5: else:
if x == 5 then else
if x == 5 else:
if x == 5: else
if x == 5: else
What is the correct way to check if a key exists in a dictionary in Python?
key in dict
dict.has_key(key)
dict.contains(key)
dict[key] != None
key in dict
What is the output of the following code:
x = "Hello, World!"
print(x[7:12])
x = "Hello, World!"
print(x[7:12])
World
Hello
World!
Hello,
World
What is the correct syntax for a try-except block in Python?
try: except ValueError:
try except ValueError
try { } catch (ValueError)
try: catch ValueError
try: except ValueError:
What is the correct way to iterate over a list in Python?
for i in list
for i in list:
for i in range(list)
for i in [0, 1, 2, ..., len(list) - 1]
for i in list:
Submit
Retry
{"qz1-335125":"5","qz1-335126":"list.remove(element)","qz1-335127":"while x < 5:","qz1-335128":"36","qz1-335129":"dict[key]","qz1-335130":"if x == 5: else","qz1-335131":"key in dict","qz1-335132":"World","qz1-335133":"try: except ValueError:","qz1-335134":"for i in list:"}
Leave a Comment