Python
50 Python Output Questions for CBSE Class 12 Board Exam
Practice 50 important Python output questions for CBSE Class 12. Covers strings, lists, tuples, dictionaries, functions and more with detailed answers.
"Predict the output" questions carry 2-3 marks each in the CBSE Class 12 board exam. These questions test your understanding of how Python evaluates expressions, handles data types, and executes code. Practice all 50 questions below to boost your confidence.
String Questions
Q1.
s = "COMPUTER SCIENCE"
print(s[3:8])
print(s[-7:])
PUTER
SCIENCE
Q2.
s = "Python"
print(s * 2)
print(s[1:4] + s[-1])
PythonPython
ythn
Q3.
s = "Hello World"
print(s.split())
print(s.replace("World", "Python"))
['Hello', 'World']
Hello Python
Q4.
s = "cbse2026"
print(s.isalpha())
print(s.isalnum())
print(s.upper())
False
True
CBSE2026
Q5.
s = "abcdef"
print(s[::2])
print(s[::-1])
ace
fedcba
Q6.
s = "Hello"
s1 = s.capitalize()
s2 = s.title()
print(s1, s2)
Hello Hello
Both capitalize() and title() capitalize the first letter of the string/words. Since "Hello" already starts with a capital letter, both return "Hello".
Q7.
s = "python programming"
print(s.count("p"))
print(s.find("gram"))
print(s.find("java"))
2
10
-1
List Questions
Q8.
L = [10, 20, 30, 40, 50]
print(L[1:4])
print(L[::-1])
[20, 30, 40]
[50, 40, 30, 20, 10]
Q9.
L = [1, 2, 3, 4, 5]
L.append([6, 7])
print(L)
print(len(L))
[1, 2, 3, 4, 5, [6, 7]]
6
append() adds the entire list as a single element. So the length is 6, not 7.
Q10.
L = [1, 2, 3, 4, 5]
L.extend([6, 7])
print(L)
print(len(L))
[1, 2, 3, 4, 5, 6, 7]
7
extend() adds each element individually, so the length is 7.
Q11.
L = [4, 1, 8, 3, 9, 2]
L.sort()
print(L)
L.sort(reverse=True)
print(L)
[1, 2, 3, 4, 8, 9]
[9, 8, 4, 3, 2, 1]
Q12.
L = [10, 20, 30, 40]
L.insert(2, 25)
print(L)
L.pop(3)
print(L)
[10, 20, 25, 30, 40]
[10, 20, 25, 40]
After inserting 25 at index 2, the element at index 3 is 30, which gets popped.
Q13.
L = [1, 2, 3]
M = L
M.append(4)
print(L)
print(M)
[1, 2, 3, 4]
[1, 2, 3, 4]
Both L and M point to the same list object. Modifying one affects the other.
Q14.
L = [1, 2, 3]
M = L.copy()
M.append(4)
print(L)
print(M)
[1, 2, 3]
[1, 2, 3, 4]
copy() creates a new list, so changes to M do not affect L.
Tuple Questions
Q15.
t = (10, 20, 30, 40, 50)
print(t[1:4])
print(t[-2])
(20, 30, 40)
40
Q16.
t = (5,)
t2 = (5)
print(type(t))
print(type(t2))
<class 'tuple'>
<class 'int'>
A trailing comma is required for a single-element tuple.
Q17.
t = (1, 2, 3, 2, 4, 2)
print(t.count(2))
print(t.index(2))
3
1
count() returns 3 because 2 appears three times. index() returns 1, the index of the first occurrence.
Dictionary Questions
Q18.
d = {"a": 1, "b": 2, "c": 3}
print(list(d.keys()))
print(list(d.values()))
['a', 'b', 'c']
[1, 2, 3]
Q19.
d = {"a": 1, "b": 2, "a": 3}
print(d)
print(len(d))
{'a': 3, 'b': 2}
2
Duplicate keys are not allowed. The last value for key "a" overwrites the first.
Q20.
d = {"x": 10, "y": 20, "z": 30}
d.pop("y")
print(d)
d["w"] = 40
print(d)
{'x': 10, 'z': 30}
{'x': 10, 'z': 30, 'w': 40}
Q21.
d = {1: "one", 2: "two", 3: "three"}
for k in d:
print(k, end=" ")
1 2 3
Looping through a dictionary iterates over its keys by default.
Function Questions
Q22.
def greet(name="Student"):
print("Hello", name)
greet("Aman")
greet()
Hello Aman
Hello Student
Q23.
def calc(a, b=2):
return a ** b
print(calc(3))
print(calc(3, 3))
9
27
Q24.
x = 10
def change():
x = 20
print("Inside:", x)
change()
print("Outside:", x)
Inside: 20
Outside: 10
The x inside the function is a local variable and does not affect the global x.
Q25.
x = 10
def change():
global x
x = 20
print("Inside:", x)
change()
print("Outside:", x)
Inside: 20
Outside: 20
The global keyword allows the function to modify the global variable.
Q26.
def func(L):
L.append(4)
return L
M = [1, 2, 3]
N = func(M)
print(M)
print(N)
[1, 2, 3, 4]
[1, 2, 3, 4]
Lists are passed by reference. The function modifies the original list.
Operator and Expression Questions
Q27.
print(17 // 5)
print(17 % 5)
print(17 / 5)
3
2
3.4
Q28.
print(2 ** 3 ** 2)
512
The ** operator is right-associative. It evaluates as 2 ** (3 ** 2) = 2 ** 9 = 512.
Q29.
print(bool(0))
print(bool(""))
print(bool([]))
print(bool("False"))
False
False
False
True
A non-empty string (even "False") is truthy.
Q30.
a = 5
b = 10
a, b = b, a + b
print(a, b)
10 15
Python evaluates the right side first: b is 10, a + b is 15. Then it assigns.
Loop Questions
Q31.
for i in range(5, 0, -1):
print(i, end=" ")
5 4 3 2 1
Q32.
for i in range(1, 6):
if i == 3:
continue
print(i, end=" ")
1 2 4 5
continue skips the rest of the loop body for that iteration.
Q33.
for i in range(1, 6):
if i == 4:
break
print(i, end=" ")
else:
print("Done")
1 2 3
The else block after a for loop runs only if the loop completes without a break. Since break was triggered, "Done" is not printed.
Q34.
i = 1
while i <= 5:
print(i, end=" ")
i += 2
1 3 5
Mixed and Tricky Questions
Q35.
print("abc" > "abd")
print("abc" > "ab")
False
True
Strings are compared character by character using ASCII values. 'c' (99) < 'd' (100), so the first is False. For the second, "abc" is longer and matches "ab" for the first two characters, so it is greater.
Q36.
print(type(3 + 4.0))
print(type(True + 3))
<class 'float'>
<class 'int'>
3 + 4.0 results in a float (type promotion). True + 3 equals 4 because True is treated as 1.
Q37.
L = [1, 2, 3, 4, 5]
print(L[10:])
[]
Slicing beyond the range does not raise an error, it returns an empty list.
Q38.
a = [1, 2, 3]
b = a[:]
b.append(4)
print(a)
[1, 2, 3]
a[:] creates a shallow copy.
Q39.
print("python"[100:200])
print("python"[2:100])
thon
The first line prints an empty string (no error). The second prints from index 2 to the end.
Q40.
d = {}
d[1] = 1
d["1"] = 2
d[1.0] = 3
print(d)
{1: 3, '1': 2}
In Python, 1 and 1.0 are equal and have the same hash, so d[1.0] = 3 overwrites d[1]. The string "1" is a different key.
Q41.
def func(a, b=[]):
b.append(a)
return b
print(func(1))
print(func(2))
[1]
[1, 2]
The default list [] is created once and reused across calls. This is a well-known Python gotcha.
Q42.
s = "Hello"
print(s.swapcase())
print(s.center(11, "*"))
hELLO
***Hello***
Q43.
print(list(range(0)))
print(list(range(1, 1)))
[]
[]
Both ranges are empty because the start is not less than the stop.
Q44.
x = [1, 2, 3]
y = [1, 2, 3]
print(x == y)
print(x is y)
True
False
== checks value equality. is checks whether both variables point to the same object in memory.
Q45.
print("Hello\tWorld\n2026")
Hello World
2026
\t inserts a tab, \n inserts a newline.
Q46.
a = "123"
b = int(a) + 1
print(b, type(b))
124 <class 'int'>
Q47.
L = [10, 20, 30]
print(sum(L))
print(min(L), max(L))
60
10 30
Q48.
s = "aAbBcC"
print(s.lower())
print(s.isupper())
print(s.islower())
aabbcc
False
False
Neither isupper() nor islower() returns True because the string has both upper and lower case characters.
Q49.
print(ord("A"))
print(chr(97))
print(ord("a") - ord("A"))
65
a
32
Q50.
a = 10
b = 20
print(a if a > b else b)
c = "Even" if a % 2 == 0 else "Odd"
print(c)
20
Even
Tips for Scoring Full Marks
- Trace the code line by line on paper. Do not try to solve it mentally.
- Watch out for mutable default arguments (Q41), this is a frequent trick question.
- Remember that
1and1.0are treated as the same dictionary key (Q40). - Pay attention to
end=" "in print statements, it changes the output format. - Know the difference between
append()andextend(), this is tested almost every year. - Understand global vs local variables clearly (Q24 and Q25).
- Remember that slicing beyond the range returns an empty sequence, not an error (Q37, Q39).
Practice writing the output by hand before checking the answers. This builds the muscle memory you need during the actual exam.
Want to learn more?
Explore free chapter-wise notes with quizzes and code playground
Prefer watching over reading?
Subscribe for free.