Board Q&A · Class 12 Computer Science

Python Revision Tour II (Strings, Lists, Tuples, Dictionaries): Class 12 CBSE Previous-Year Questions with Answers

CBSE Question Papers →

65 questions from CBSE board, sample and compartment papers (2024–2027), 1 to 3 marks, each with a model answer. Questions on strings, lists, tuples and dictionaries: slicing and indexing, built-in methods such as split(), find(), index(), insert(), remove() and update(), mutable and immutable types, and predicting the output of code that uses them. Programming answers open in the Python Lab.

Showing 65 of 295 questions
Group

Python Revision Tour II

65 Questions
Python Revision Tour II· 1 Mark· Q7· 2024 Board Paper
Identify the invalid Python statement from the following:
  1. (A)d = dict()
  2. (B)e = {}
  3. (C)f = []
  4. (D)g = dict{}
Python Revision Tour II· 1 Mark· Q8· 2024 Board Paper Python
Consider the statements given below and then choose the correct output from the given options: myStr="MISSISSIPPI" print(myStr[:4]+"#"+myStr[-5:])
  1. (A)MISSI#SIPPI
  2. (B)MISS#SIPPI
  3. (C)MISS#IPPIS
  4. (D)MISSI#IPPIS
Python Revision Tour II· 1 Mark· Q10· 2024 Board Paper Python
Select the correct output of the following code: event="G20 Presidency@2023" L=event.split(' ') print(L[::-2])
  1. (A)'G20'
  2. (B)['Presidency@2023']
  3. (C)['G20']
  4. (D)'Presidency@2023'
Python Revision Tour II· 1 Mark· Q18· 2024 Board Paper
Assertion (A): The expression "HELLO".sort() in Python will give an error. Reason (R): sort() does not exist as a method/function for strings in Python. Mark the correct choice as:
  1. (A)Both (A) and (R) are true and (R) is the correct explanation for (A).
  2. (B)Both (A) and (R) are true and (R) is not the correct explanation for (A).
  3. (C)(A) is true but (R) is false.
  4. (D)(A) is false but (R) is true.
Python Revision Tour II· 2 Marks· Q22· 2024 Board Paper Python
Write the output displayed on execution of the following Python code: LS=["HIMALAYA", "NILGIRI", "ALASKA", "ALPS"] D={} for S in LS : if len(S)%4 == 0: D[S] = len(S) for K in D : print(K,D[K], sep = "#")
Python Revision Tour II· 2 Marks· Q23· 2024 Board Paper Python
(A) Write the Python statement for each of the following tasks using built-in functions/methods only: (i) To remove the item whose key is "NISHA" from a dictionary named Students. For example, if the dictionary Students contains {"ANITA":90, "NISHA":76, "ASHA":92}, then after removal the dictionary should contain {"ANITA":90, "ASHA":92} (ii) To display the number of occurrences of the substring "is" in a string named message. For example if the string message contains "This is his book", then the output will be 3. OR (B) A tuple named subject stores the names of different subjects. Write the Python commands to convert the given tuple to a list and thereafter delete the last element of the list.
Python Revision Tour II· 3 Marks· Q26· 2024 Board Paper Python
Write the output on execution of the following Python code: S="Racecar Car Radar" L=S.split() for W in L : x=W.upper() if x==x[::-1]: for I in x: print(I,end="*") else: for I in W: print(I,end="#") print()
Python Revision Tour II· 1 Mark· Q1· 2025 Board Paper
State True or False: "A Python List must always contain all its elements of same data type."
Python Revision Tour II· 1 Mark· Q3· 2025 Board Paper Python
Identify the correct output of the following code snippet: game="Olympic2024" print(game.index("C"))
  1. (A)0
  2. (B)6
  3. (C)-1
  4. (D)ValueError
Python Revision Tour II· 1 Mark· Q6· 2025 Board Paper Python
Consider the statements given below and then choose the correct output from the given options: L=['TIC', 'TAC'] print(L[::-1])
  1. (A)['CIT', 'CAT']
  2. (B)['TIC', 'TAC']
  3. (C)['CAT', 'CIT']
  4. (D)['TAC', 'TIC']
Python Revision Tour II· 1 Mark· Q8· 2025 Board Paper Python
Consider the statements given below and then choose the correct output from the given options: D={'S01':95, 'S02':96 } for I in D : print(I,end='#')
  1. (A)S01#S02#
  2. (B)95#96#
  3. (C)S01,95#S02,96#
  4. (D)S01#95#S02#96#
Python Revision Tour II· 1 Mark· Q12· 2025 Board Paper
Which of the following built-in function/method returns a dictionary?
  1. (A)dict()
  2. (B)values()
  3. (C)keys()
  4. (D)items()
Python Revision Tour II· 2 Marks· Q24· 2025 Board Paper Python
Consider the following dictionaries, D and D1: D={"Suman": 40, "Raj":55, "Raman":60} D1={"Aditi":30, "Amit":90,"Raj":20} (Answer using built-in Python functions only) (i) (a) Write a statement to display/return the value corresponding to the key "Raj" in the dictionary D. OR (b) Write a statement to display the length of the dictionary D1. (ii) (a) Write a statement to append all the key-value pairs of the dictionary D to the dictionary D1. OR (b) Write a statement to delete the item with the given key "Amit" from the dictionary D1.
Python Revision Tour II· 3 Marks· Q31· 2025 Board Paper Python
Predict the output of the following code: def ExamOn(mystr): newstr = "" count = 0 for i in mystr: if count%2 != 0: newstr = newstr + str(count-1) else: newstr = newstr + i.lower() count += 1 newstr = newstr + mystr[:2] print("The new string is:", newstr) ExamOn("GenX")
Python Revision Tour II· 3 Marks· Q31· 2025 Board Paper Python
Write the output on execution of the following Python code: def Change(X): for K,V in X.items(): L1.append(K) L2.append(V) D={1:"ONE",2:"TWO",3:"THREE"} L1=[] L2=[] Change(D) print(L1) print(L2) print(D)
Python Revision Tour II· 1 Mark· Q2· 2026 Board Paper Python
Identify the output of the following code snippet: s = "the Truth" print(s.capitalize())
  1. (A)The truth
  2. (B)THE TRUTH
  3. (C)The Truth
  4. (D)the Truth
Python Revision Tour II· 1 Mark· Q4· 2026 Board Paper Python
What is the output of the following code snippet? s = 'War and Peace by Leo Tolstoy' print(s.partition("by"))
  1. (A)('War and Peace ', 'by', ' Leo Tolstoy')
  2. (B)['War and Peace ', 'by', ' Leo Tolstoy']
  3. (C)('War and Peace ', ' Leo Tolstoy')
  4. (D)['War and Peace ', ' Leo Tolstoy']
Python Revision Tour II· 1 Mark· Q5· 2026 Board Paper Python
What will be the output of the following statement? print("PythonProgram"[-1:2:-2])
Python Revision Tour II· 1 Mark· Q6· 2026 Board Paper Python
What will be the output of the following code snippet? t = tuple('tuple') t2 = t[2], t += t2 print(t)
  1. (A)('tuple')
  2. (B)('tuple', 'p')
  3. (C)('t', 'u', 'p', 'l', 'e', 'p')
  4. (D)('t', 'u', 'p', 'l', 'e')
Python Revision Tour II· 1 Mark· Q7· 2026 Board Paper
Which of the following statements is true about dictionaries in Python?
  1. (A)A dictionary is an example of sequence datatype.
  2. (B)A dictionary cannot have two elements with same key.
  3. (C)A dictionary cannot have two elements with same value.
  4. (D)The key and value of an element cannot be the same.
Python Revision Tour II· 1 Mark· Q8· 2026 Board Paper Python
If L is a list with 6 elements, then which of the following statements will raise an exception?
  1. (A)L.pop(1)
  2. (B)L.pop(6)
  3. (C)L.insert(1, 6)
  4. (D)L.insert(6, 1)
Python Revision Tour II· 1 Mark· Q20· 2026 Board Paper
Assertion (A): [1, 2, 3] + '123' is an invalid expression in Python. Reason (R): In Python, a list cannot be concatenated with a string.
Python Revision Tour II· 2 Marks· Q23· 2026 Board Paper Python
Write a Python statement to perform the following tasks: (USE BUILT_IN FUNCTIONS/METHODS ONLY) (i) To create a new list L1 containing the elements of list L arranged in ascending order, without modifying list L. (ii) A statement to check whether the given character, ch is an alphabet or a number.
Python Revision Tour II· 2 Marks· Q24· 2026 Board Paper Python
Assuming that D1 is a dictionary in Python, (i) (a) Write a Python expression to check if the key, 'RNo' is present in D1. OR (b) Write a Python expression to check if any key in D1 has a value 12. (ii) (a) Write a single statement using a BUILT_IN function to add the key: value pair 'RNo': 12, if the key 'RNo' is not present in D1. However, if the key 'RNo' is present, the function should return its value. OR (b) Write a single statement to delete all the elements from D1.
Python Revision Tour II· 3 Marks· Q31· 2026 Board Paper Python
(a) Write output: def Exam2026(given): new=[]; for ch in given[1:-1]: if ch.isupper(): new.reverse() elif ch not in new: new.append(ch) elif ch in new: new.pop(); print(new); Exam2026("Gold-24Medals") OR (b) Write output: def Exam2026(given): new=0; while given: if new%2: new+=given%10 else: new+=given%5; print(new,end='-'); given//=10; Exam2026(123456)
Python Revision Tour II· 1 Mark· Q1· 2025 Compartment Paper
State if following statement is True or False: If T is a tuple and L is a list, then T+L is a valid statement in Python.
Python Revision Tour II· 1 Mark· Q2· 2025 Compartment Paper Python
Identify the output of the following code segment: s = "an apple. a toy." s = s.find('a', 2) print(s)
  1. (A)0
  2. (B)1
  3. (C)3
  4. (D)'a'
Python Revision Tour II· 1 Mark· Q4· 2025 Compartment Paper Python
What is the output of the following expression? Sports="Paralympic Games" print(Sports.split("m"))
  1. (A)['Paraly', 'm', 'pic Ga', 'm','es']
  2. (B)('Paraly', 'm', 'pic Games')
  3. (C)('Paraly', 'pic Ga','es')
  4. (D)['Paraly', 'pic Ga','es']
Python Revision Tour II· 1 Mark· Q5· 2025 Compartment Paper Python
What will be the output of the following code segment? p = list("Session 2024-25") print(p[10:20:])
Python Revision Tour II· 1 Mark· Q6· 2025 Compartment Paper
Which of the following is a mapped data type?
  1. (A)List
  2. (B)Sets
  3. (C)Dictionary
  4. (D)Boolean
Python Revision Tour II· 1 Mark· Q7· 2025 Compartment Paper
If the dictionary D1 is defined as: D1={1:'a', 2:'b'}, then which of the following statements is incorrect and hence will result in an error?
  1. (A)D1.get(1)
  2. (B)D1.get(3)
  3. (C)D1.del(1)
  4. (D)D1.clear()
Python Revision Tour II· 1 Mark· Q8· 2025 Compartment Paper
Which of the following list methods accepts exactly 2 parameters?
  1. (A)append()
  2. (B)extend()
  3. (C)insert()
  4. (D)pop()
Python Revision Tour II· 2 Marks· Q24· 2025 Compartment Paper Python
Assuming that D1 and D2 are Python dictionaries. Write statements using built-in functions: (I)(a) Delete all elements of D1 OR (b) Generate a list of values of D1. (II)(a) Update dictionary D2 with elements of D1 OR (b) Generate a tuple of keys of D2.
Python Revision Tour II· 3 Marks· Q31· 2025 Compartment Paper Python
(a) Write the output on execution of the following Python code: P = [3, 5, 7, 4] P.insert(2, 3) P.extend([10, 6]) print(P) print(P.index(7)) print(P[::2]) OR (b) Output of the ALTER function execution.
Python Revision Tour II· 1 Mark· Q4· 2024 Sample Paper Python
Select the correct output of the code: s = "Python is fun" l = s.split() s_new = "-".join([l[0].upper(), l[1], l[2].capitalize()]) print(s_new)
  1. (A)a. PYTHON-IS-Fun
  2. (B)b. PYTHON-is-Fun
  3. (C)c. Python-is-fun
  4. (D)d. PYTHON-Is -Fun
Python Revision Tour II· 1 Mark· Q7· 2024 Sample Paper
Which of the following will delete key-value pair for key = “Red” from a dictionary D1?
  1. (A)a. delete D1("Red")
  2. (B)b. del D1["Red"]
  3. (C)c. del.D1["Red"]
  4. (D)d. D1.del["Red"]
Python Revision Tour II· 1 Mark· Q8· 2024 Sample Paper Python
Consider the statements given below and then choose the correct output from the given options: pride="#G20 Presidency" print(pride[-2:2:-2])
  1. (A)a. ndsr
  2. (B)b. ceieP0
  3. (C)c. ceieP
  4. (D)d. yndsr
Python Revision Tour II· 1 Mark· Q9· 2024 Sample Paper
Which of the following statement(s) would give an error during execution of the following code? tup = (20,30,40,50,80,79) print(tup) #Statement 1 print(tup[3]+50) #Statement 2 print(max(tup)) #Statement 3 tup[4]=80 #Statement 4
  1. (A)a. Statement 1
  2. (B)b. Statement 2
  3. (C)c. Statement 3
  4. (D)d. Statement 4
Python Revision Tour II· 2 Marks· Q22· 2024 Sample Paper Python
Predict the output of the following code: S = "LOST" L = [10,21,33,4] D={} for I in range(len(S)): if I%2==0: D[L.pop()] = S[I] else: D[L.pop()] = I+3 for K,V in D.items(): print(K,V,sep="*")
Python Revision Tour II· 2 Marks· Q23· 2024 Sample Paper Python
Write the Python statement for each of the following tasks using BUILT-IN functions/methods only: (i) To insert an element 200 at the third position, in the list L1. (ii) To check whether a string named, message ends with a full stop / period or not. OR A list named studentAge stores age of students of a class. Write the Python command to import the required module and (using built-in function) to display the most common age value from the given list.
Python Revision Tour II· 3 Marks· Q26· 2024 Sample Paper Python
Predict the output of the Python code given below: Text1="IND-23" Text2="" I=0 while I<len(Text1): if Text1[I]>="0" and Text1[I]<="9": Val = int(Text1[I]) Val = Val + 1 Text2=Text2 + str(Val) elif Text1[I]>="A" and Text1[I]<="Z": Text2=Text2 + (Text1[I+1]) else: Text2=Text2 + "*" I+=1 print(Text2)
Python Revision Tour II· 1 Mark· Q2· 2025 Sample Paper Python
Identify the output of the following code snippet: text = "PYTHONPROGRAM" text=text.replace('PY','#') print(text)
  1. (A)#THONPROGRAM
  2. (B)##THON#ROGRAM
  3. (C)#THON#ROGRAM
  4. (D)#YTHON#ROGRAM
Python Revision Tour II· 1 Mark· Q4· 2025 Sample Paper Python
What is the output of the expression? country='International' print(country.split("n"))
  1. (A)('I', 'ter', 'atio', 'al')
  2. (B)['I', 'ter', 'atio', 'al']
  3. (C)['I', 'n', 'ter', 'n', 'atio', 'n', 'al']
  4. (D)Error
Python Revision Tour II· 1 Mark· Q5· 2025 Sample Paper Python
What will be the output of the following code snippet? message= "World Peace" print(message[-2::-2])
Python Revision Tour II· 1 Mark· Q6· 2025 Sample Paper Python
What will be the output of the following code? tuple1 = (1, 2, 3) tuple2 = tuple1 tuple1 += (4,) print(tuple1 == tuple2)
  1. (A)True
  2. (B)False
  3. (C)tuple1
  4. (D)Error
Python Revision Tour II· 1 Mark· Q7· 2025 Sample Paper Python
If my_dict is a dictionary as defined below, then which of the following statements will raise an exception? my_dict = {'apple': 10, 'banana': 20, 'orange': 30}
  1. (A)my_dict.get('orange')
  2. (B)print(my_dict['apple', 'banana'])
  3. (C)my_dict['apple']=20
  4. (D)print(str(my_dict))
Python Revision Tour II· 1 Mark· Q8· 2025 Sample Paper
What does the list.remove(x) method do in Python?
  1. (A)Removes the element at index x from the list
  2. (B)Removes the first occurrence of value x from the list
  3. (C)Removes all occurrences of value x from the list
  4. (D)Removes the last occurrence of value x from the list
Python Revision Tour II· 2 Marks· Q24· 2025 Sample Paper Python
If L1=[1,2,3,2,1,2,4,2, . . . ], and L2=[10,20,30, . . .], then (Answer using builtin functions only) (I) A) Write a statement to count the occurrences of 4 in L1. OR B) Write a statement to sort the elements of list L1 in ascending order. (II) A) Write a statement to insert all the elements of L2 at the end of L1. OR B) Write a statement to reverse the elements of list L2.
Python Revision Tour II· 3 Marks· Q31· 2025 Sample Paper Python
Predict the output of the following code: d = {"apple": 15, "banana": 7, "cherry": 9} str1 = "" for key in d: str1 = str1 + str(d[key]) + "@" + "\n" str2 = str1[:-1] print(str2) OR Predict the output of the following code: line=[4,9,12,6,20] for I in line: for j in range(1,I%5): print(j,'#',end="") print()
Python Revision Tour II· 1 Mark· Q2· 2026 Sample Paper Python
What will be the output of the following code? L = ["India", "Incredible", "Bharat"] print(L[1][0] + L[2][-1])
  1. (A)IT
  2. (B)it
  3. (C)It
  4. (D)iT
Python Revision Tour II· 1 Mark· Q5· 2026 Sample Paper Python
What will be the output of the following Python code? str= "Soft Skills" print(str[-3::-3])
  1. (A)lSf
  2. (B)Stkl
  3. (C)StKi
  4. (D)l
Python Revision Tour II· 1 Mark· Q10· 2026 Sample Paper Python
What will be the output of the following Python code? my_dict = {"name": "Alicia", "age": 27, "city": "DELHI"} print(my_dict.get("profession", "Not Specified"))
  1. (A)Alicia
  2. (B)DELHI
  3. (C)None
  4. (D)Not Specified
Python Revision Tour II· 1 Mark· Q14· 2026 Sample Paper Python
What is the output of the given Python code? st='Waterskiing is thrilling!' print(st.split("i"))
  1. (A)['Watersk', 'ng ', 's thr', 'll', 'ng!']
  2. (B)['Watersk', '', 'ng ', 's thr', 'll', 'ng!']
  3. (C)['Watersk', 'i', 'ng ', 's thr', 'll', 'ng!']
  4. (D)Error
Python Revision Tour II· 1 Mark· Q20· 2026 Sample Paper
Assertion (A): The expression (1, 2, 3, 4).append(5) in Python will modify the original sequence datatype. Reason (R): The append() method adds an element to the end of a list and modifies the list in place.
  1. (A)Both A and R are True and R is the correct explanation for A
  2. (B)Both A and R are True and R is not the correct explanation for A
  3. (C)A is True but R is False
  4. (D)A is False but R is True
Python Revision Tour II· 2 Marks· Q24· 2026 Sample Paper Python
A. (Answer using Python built-in methods/functions only): I. Write a statement to find the index of the first occurrence of the substring "good" in a string named review. II. Write a statement to sort the elements of list L1 in descending order. 2025-26. OR B. Predict the output of the following Python code: text="Learn Python with fun and practice" print(text.partition("with")) print(text.count("a"))
Python Revision Tour II· 2 Marks· Q26· 2026 Sample Paper Python
Predict the output of the Python code given below: emp = {"Arv": (85000,90000),"Ria": (78000,88000),"Jay": (72000,80000),"Tia": (80000,70000)} selected = [ ] for name in emp: salary = emp[name] average = (salary[0] + salary[1]) / 2 if average > 80000: selected.append(name) print(selected)
Python Revision Tour II· 3 Marks· Q31· 2026 Sample Paper Python
A. Predict the output of the following Python code: s1="SQP-25" s2="" i=0 while i<len(s1): if s1[i]>='0' and s1[i]<='9': Num=int(s1[i]) Num-=1 s2=s2+str(Num) elif s1[i]>='A' and s1[i]<='Z': s2=s2+s1[i+1] else: s2=s2+'^' i+=1 print(s2) OR B. Predict the output of the following Python code: wildlife_sanctuary = ["Kaziranga", "Ranthambhore", "Jim Corbett", "Sundarbans", "Periyar", "Gir", "Bandipur"] output = [ ] for sanctuary in wildlife_sanctuary: if sanctuary[-1] in 'aeiou': output.append(sanctuary[0].upper()) print(output)
Python Revision Tour II· 1 Mark· Q1· 2027 Sample Paper Python
Write the output on execution of the following Python code: L1=[10,20,25,30] L1.insert(1,15) print(L1)
Python Revision Tour II· 1 Mark· Q2· 2027 Sample Paper Python
What will be the output of the following expression? Msg = "programming is amazing" print(Msg.split("m"))
  1. (A)['progra', '', 'ing is a', 'azing']
  2. (B)['progra', 'ming is a', 'azing']
  3. (C)('progra', '', 'ing is amazing')
  4. (D)['program', 'ing is a', 'zing']
Python Revision Tour II· 1 Mark· Q5· 2027 Sample Paper
Consider the following Python code: t = (1, 2, 3) l = [4, 5] print(t + l) What will happen when this code is executed?
  1. (A)[1, 2, 3, 4, 5]
  2. (B)(1, 2, 3, 4, 5)
  3. (C)Error, because a tuple cannot be concatenated with a list
  4. (D)((1, 2, 3), [4, 5])
Python Revision Tour II· 1 Mark· Q7· 2027 Sample Paper Python
Predict the output for the following: Dl={"Pen":12, "Pencil":6, "Scale":5, "InkPen":20} print(12 in Dl)
  1. (A)False
  2. (B)Error
  3. (C)None
  4. (D)True
Python Revision Tour II· 1 Mark· Q18· 2027 Sample Paper Python
What will be the output of the following Python code? text = "Drone Expo" print(text[-2: :-4])
Python Revision Tour II· 2 Marks· Q23· 2027 Sample Paper Python
The Python program below tries to print the list in reverse. However, there are syntax and logical errors in the code. Rewrite it after removing all the errors. Also, underline all the corrections made words=["Class Test","Term Exams","Pre-board Exam","Board Exam'] L=len(words) for i in range(L, -1, -1) Print (words[i] , end = " ")
Python Revision Tour II· 2 Marks· Q25· 2027 Sample Paper Python
A. (Answer using Python built-in methods/functions only): I. Write a statement to check whether the string username starts with "admin". II. Given data = [2, 7, 9, 9, 2], write a statement to count how many times the largest element occurs. OR B. Predict the output of the following Python code: text = "Python Programming" print(text.replace("o", "0")) print(text.find("z"))
Python Revision Tour II· 2 Marks· Q26· 2027 Sample Paper Python
Predict the output of the following Python code: code = "gLaD5" result = [] i = 0 while i < len(code): if code[i].isupper(): result.append(code[i].lower()) elif code[i].isdigit(): result.append(int(code[i]) * 2) else: result.append("#") i += 1 print(result)