Show List
Quiz - Python - 1
Select the right answer for below questions:
What is the correct syntax for defining a function in Python?
def my_function():
function my_function():
my_function = def():
function def my_function():
def my_function():
What is the output of the following code:
x = [1, 2, 3, 4, 5]
print(x[2:4])
x = [1, 2, 3, 4, 5]
print(x[2:4])
[2, 3, 4]
[3, 4, 5]
[1, 2, 3]
[2, 3]
[2, 3]
What is the correct way to convert a string to a list in Python?
list(string)
string.list()
[string]
string.split()
list(string)
What is the correct way to create a dictionary in Python?
dict = {'key1': 'value1', 'key2': 'value2'}
{'key1': 'value1', 'key2': 'value2'} = dict
dict('key1': 'value1', 'key2': 'value2')
{'key1': 'value1', 'key2': 'value2'}
{'key1': 'value1', 'key2': 'value2'}
What is the correct syntax for a for loop in Python?
for i in range(5):
for (i = 0; i < 5; i++):
for i in 5:
for i in [0, 1, 2, 3, 4]:
for i in range(5):
What is the correct way to define a class in Python?
class MyClass:
class MyClass():
def class MyClass:
def MyClass():
class MyClass:
What is the correct syntax for importing a module in Python?
import module
include module
#include
require module
import module
What is the output of the following code:
x = 5
y = 10
print(x == y)
x = 5
y = 10
print(x == y)
TRUE
FALSE
5
10
FALSE
What is the correct way to raise an exception in Python?
raise ValueError
throw ValueError
ValueError()
ValueError.raise()
raise ValueError
What is the correct syntax for an if statement in Python?
if x == 5:
if (x == 5)
if x = 5
if x = 5 then
if x == 5:
Submit
Retry
{"qz1-627207":"def my_function():","qz1-627208":"[2, 3]","qz1-627209":"list(string)","qz1-627210":"{'key1': 'value1', 'key2': 'value2'}","qz1-627211":"for i in range(5):","qz1-627212":"class MyClass:","qz1-627213":"import module","qz1-627214":"FALSE","qz1-627215":"raise ValueError","qz1-627216":"if x == 5:"}
Leave a Comment