Show List
Quiz - Python - 4
Select the right answer for below questions:
What is the output of the following code:
x = 5
y = 3
print(x % y)
x = 5
y = 3
print(x % y)
1
2
3
8
2
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))
4
5
6
7
5
What is the correct syntax to create a class in Python?
class name:
class name(object):
class object:
class name:
def init(self):
def init(self):
class name(object):
What is the correct syntax to raise an exception in Python?
raise Exception("error message")
throw Exception("error message")
raise("error message")
throw("error message")
raise Exception("error message")
What is the output of the following code:
x = 10
y = 5
print(x / y)
x = 10
y = 5
print(x / y)
1
2
2
1
2
What is the correct way to iterate over a dictionary in Python?
for x in dict:
for x in dict.keys():
for x, y in dict.items():
for x in dict.values():
for x, y in dict.items():
What is the output of the following code:
x = "Hello, World!"
print(x[0:5])
x = "Hello, World!"
print(x[0:5])
World
Hello
Hello,
, Worl
Hello
What is the correct syntax for a while loop in Python?
while x < 5:
while x < 5
while (x < 5):
while x < 5 {
while x < 5:
What is the output of the following code:
x = [1, 2, 3, 4, 5]
x.append(6)
print(x)
x = [1, 2, 3, 4, 5]
x.append(6)
print(x)
[1, 2, 3, 4, 5, 6, 7]
[1, 2, 3, 4, 5, 6]
[1, 2, 3, 4, 6]
[6, 1, 2, 3, 4, 5]
[1, 2, 3, 4, 5, 6]
What is the correct syntax for a for loop in Python?
for x in range(5):
for (x in range(5)):
for x in range 5:
for x in range(5);
for x in range(5):
Submit
Retry
{"qz1-517404":"2","qz1-517405":"5","qz1-517406":"class name(object):","qz1-517407":"raise Exception(\"error message\")","qz1-517408":"2","qz1-517409":"for x, y in dict.items():","qz1-517410":"Hello","qz1-517411":"while x < 5:","qz1-517412":"[1, 2, 3, 4, 5, 6]","qz1-517413":"for x in range(5):"}
Leave a Comment