Question 1
What is the role of syntax in Python programming?
A) It defines how fast the code runs
B) It specifies the rules for writing valid code
C) It determines the memory usage of a program
D) It controls the output format
Question 2
What will the following code print?
print(0x1A)
A) 26
B) 16
C) 10
D) Error
Question 3
Which is a reserved Python keyword?
A) begin
B) or
C) start
D) run
Question 4
What will print(5 | 3) output?
A) 8
B) 7
C) 15
D) Error
Question 5
What is the purpose of a multi-line comment in Python?
A) To execute multiple lines of code
B) To document code using ''' or """
C) To define a function
D) To loop through code
Question 6
What is the data type of True?
A) int
B) str
C) bool
D) float
Question 7
What will the following code print?
x = 6
x -= 2
print(x)
A) 8
B) 4
C) 2
D) Error
Question 8
What is the output of:
print("Python"[2:5])
A) Pyt
B) tho
C) yth
D) Error
Question 9
What will print(float("3") + int("2")) output?
A) 5.0
B) 5
C) "5"
D) Error
Question 10
What is the result of "Fun" + "!" * 3?
A) Fun!!!
B) Fun!
C) FunFunFun
D) Error
Question 11
Which variable name is valid?
A) my-var
B) myVar
C) var#1
D) 3var
Question 12
What will the following code print?
x = 25
if x < 20:
print("Small")
elif x < 30:
print("Medium")
else:
print("Large")
A) Small
B) Medium
C) Large
D) Error
Question 13
What is the output of:
for i in range(1, 5, 2):
print(i, end=" ")
A) 1 3
B) 1 2 3 4
C) 2 4
D) 1 3 5
Question 14
What will the following code print?
x = 9
while x > 6:
print(x)
x -= 2
A) 9 7
B) 9 8 7 6
C) 8 6
D) 7 5
Question 15
What is the output of:
for i in range(5):
if i % 2 == 0:
continue
print(i)
A) 0 2 4
B) 1 3
C) 0 1 2 3 4
D) Error
Question 16
What does 3 <= 5 and 2 != 2 evaluate to?
A) True
B) False
C) None
D) Error
Question 17
What is the output of:
for i in range(2):
for j in range(3):
print(i + j, end=" ")
A) 0 1 2
B) 0 1 2 1 2 3
C) 1 2 3
D) 0 1 2 3 4 5
Question 18
What will the following code print?
x = 2
while x < 6:
x += 1
print(x, end=" ")
A) 2 3 4 5
B) 3 4 5 6
C) 2 3 4
D) 6 5 4
Question 19
What does the continue statement do in a loop?
A) Exits the loop entirely
B) Skips the current iteration
C) Repeats the current iteration
D) Pauses the loop
Question 20
Which condition evaluates to True?
A) 2 < 1
B) 4 == 5
C) 3 >= 2
D) 5 != 5
Question 21
What will the following code print?
def double(num):
return num * 2
print(double(5))
A) 10
B) 5
C) 25
D) Error
Question 22
What is the output of:
tup = (4, 8, 12, 16)
print(tup[1:3])
A) (4, 8)
B) (8, 12)
C) (12, 16)
D) Error
Question 23
What will the following code print?
d = {"name": "Bob", "age": 30}
print(d["name"])
A) Bob
B) 30
C) name
D) Error
Question 24
What is the output of:
def modify(x):
x = 0
num = 10
modify(num)
print(num)
A) 0
B) 10
C) None
D) Error
Question 25
What will the following code print?
lst = [4, 2, 6]
lst.sort(reverse=True)
print(lst[0])
A) 2
B) 4
C) 6
D) Error
Question 26
What is the output of:
tup = (2, 2, 3)
print(tup.index(2))
A) 0
B) 1
C) 2
D) Error
Question 27
What will the following code print?
d = {"x": 1}
d["y"] = 2
print(d.keys())
A) ["x"]
B) ["x", "y"]
C) ["y"]
D) Error
Question 28
What is the output of:
def calc(a, b=3):
return a + b
print(calc(4))
A) 7
B) 4
C) 3
D) Error
Question 29
What will the following code print?
lst = [1, 2, 3]
lst.append(4)
print(lst)
A) [1, 2, 3]
B) [1, 2, 3, 4]
C) [4, 1, 2, 3]
D) Error
Question 30
What will [x**2 for x in range(3)] produce?
A) [0, 1, 4]
B) [1, 4, 9]
C) [0, 1, 2]
D) Error