How do you insert comments in Python code?
a) # This is a comment
What is the correct file extension for Python files?
c) .py
Which one is a correct variable assignment in Python?
c) x = 5
How do you create a function in Python?
How do you call a function in Python named 'myFunction'?
b) myFunction()
Which of the following is a correct way to create a list in Python?
c) myList = []
What is the correct way to create a dictionary in Python?
a) myDict = {}
Which method can be used to return the length of a list?
a) len()
How do you check for equality in Python?
b) ==
Which of the following is a correct if statement in Python?
a) if x == y:
How do you insert an element at the end of a list in Python?
b) myList.append("element")
What is the correct way to import a module named 'math'?
a) import math
How do you check if a list contains a specific element in Python?
a) if "element" in myList:
How can you remove an element from a list?
a) myList.remove(1)
b) myList().remove("element")
c) myList().pop(1)
d) myList.remove("element")
d) myList.remove("element")
Which of the following is not a correct if statement in Python?
b) if x = y:
What will be the output of the following code?
def func(a, b=5, c=10):
print(a, b, c)
func(1, c=20)
c) 1 5 20
What is the output of the following code?
my_list = [1, 2, 3, 4]
print(my_list[1])
b) 2
Identify the error in the following code:
def divide(a, b):
return a / b
print(divide(10, 0))
ZeroDivisionError
Identify the error in the following code:
fruits = ["apple", "banana", "cherry"]
print(fruits[3])
IndexError
Identify the error in the following code:
for i in range(10):
print(i * 2)
IndentationError / Spacing Error
What's the error in this code:
while True
print("Infinite loop")
SyntaxError / missing ":"
What's the error in this code:
my_list = [1, 2, 3]
my_list.append(4, 5)
print(my_list)
TypeError /
append() can be given just 1 argument rather than 2
What's the error in this code:
x = "Hello"
y = 5
print(x + y)
TypeError
You can't concatenate strings and integers
What's the error in this code:
def square(number):
return number ** 2
result = square[5]
print(result)
square is a function not a list
() should be used instead of []
What does the following list comprehension return?
[x**2 for x in range(1,5) if x % 2 == 0]
c) [4, 16]