Question 1
What is the output of the following code?
print(0b110 + 0o7)
A) 13
B) 11
C) 18
D) 9
Question 2
Which of the following is a valid Python keyword?
A) method
B) return
C) func
D) variable
Question 3
What will the following code print?
print(3 ** 2 % 5)
A) 4
B) 9
C) 1
D) 0
Question 4
Which is the correct way to write a multi-line comment in Python?
A) /* This is a comment */
B) # This is a comment (use # for each line)
C)
D) // This is a comment
Question 5
What is the hexadecimal literal for decimal 15?
A) 0b1111
B) 0o17
C) 0xF
D) 0d15
Question 6
What is the data type of True?
A) str
B) int
C) bool
D) float
Question 7
What will the following code print?
print("Data"[1:3])
A) Dat
B) at
C) ata
D) ta
Question 8
What is the result of int(4.7) + float("2.3")?
A) 6.3
B) 7.0
C) 6.0
D) Error
Question 9
Which variable name is invalid?
A) _data
B) data_2
C) 2data
D) dataVar
Question 10
What will print(4 > 2 or 3 < 1) output?
A) True
B) False
C) None
D) Error
Question 11
What is the output of:
print("AB" + str(3))
A) AB3
B) AB + 3
C) 3AB
D) Error
Question 12
What will the following code print?
x = 6
if x % 3 == 0:
print("Divisible")
else:
print("Not")
A) Divisible
B) Not
C) Nothing
D) Error
Question 13
What is the output of:
for i in range(2, 6, 3):
print(i, end=" ")
A) 2 5
B) 2 3 4 5
C) 2 5
D) 3 6
Question 14
What will the following code print?
x = 4
while x > 1:
print(x)
x -= 1
A) 4 3 2
B) 4 3 2 1
C) 1 2 3 4
D) 3 2 1
Question 15
What does this code print?
for i in range(5):
if i == 2:
continue
if i == 4:
break
print(i, end=" ")
A) 0 1 3
B) 0 1 3 4
C) 0 1 2 3
D) 2 4
Question 16
What will the following code print?
x = 9
if x > 10:
print("A")
elif x > 8:
print("B")
else:
print("C")
A) A
B) B
C) C
D) Error
Question 17
What is the output of:
for i in range(3):
for j in range(1):
print(i, end=" ")
A) 0 1 2
B) 0 0 1 1 2 2
C) 1 1 1
D) Error
Question 18
What will the following code print?
x = 0
while x < 3:
x += 1
if x % 2 == 0:
continue
print(x)
A) 1 3
B) 1 2 3
C) 2
D) 0 1 2
Question 19
What is the output of:
x = 7
if not (x <= 5 or x >= 10):
print("Yes")
else:
print("No")
A) Yes
B) No
C) Nothing
D) Error
Question 20
What will the following code print?
def multiply(a, b=3):
return a * b
print(multiply(2))
A) 5
B) 6
C) 3
D) Error
Question 21
What is the output of:
tup = (4, 5, 6)
print(tup[-2])
A) 4
B) 5
C) 6
D) Error
Question 22
What will the following code print?
dic = {"key1": "val1", "key2": "val2"}
print(dic.get("key3", "default"))
A) val1
B) val2
C) default
D) Error
Question 23
What is the output of:
def func(x):
x = 8
y = 3
func(y)
print(y)
A) 8
B) 3
C) None
D) Error
Question 24
What will the following code print?
lst = [5, 1, 9]
lst.sort()
print(lst[1])
A) 5
B) 1
C) 9
D) Error
Question 25
What is the output of:
tup = (1, 2, 3) + (4,)
print(len(tup))
A) 3
B) 4
C) 5
D) Error
Question 26
What will the following code print?
dic = {"a": 10}
dic["b"] = 20
print("a" in dic)
A) True
B) False
C) 10
D) Error
Question 27
What is the output of:
def subtract(x, y):
return x - y
print(subtract(y=2, x=5))
A) 3
B) -3
C) 7
D) Error
Question 28
What will the following code print?
lst = [10, 20]
lst.append(30)
print(lst.pop(0))
A) 10
B) 20
C) 30
D) Error
Question 29
What is the output of:
def test():
return "Done"
print(test())
A) Done
B) None
C) test
D) Error
Question 30
What will the following code print?
dic = {"x": 1, "y": 2}
del dic["x"]
print(len(dic))
A) 2
B) 1
C) 0
D) Error