0% found this document useful (0 votes)
12 views35 pages

Python Fundamentals: Identifiers & Data Types

The document consists of multiple-choice questions and answers related to Python programming concepts, covering topics such as identifiers, data types, operators, strings, lists, tuples, and dictionaries. Each question includes the year, the question itself, and the correct answer with explanations where necessary. It also includes programming tasks and clarifications on Python syntax and behavior.

Uploaded by

holdon99wait
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views35 pages

Python Fundamentals: Identifiers & Data Types

The document consists of multiple-choice questions and answers related to Python programming concepts, covering topics such as identifiers, data types, operators, strings, lists, tuples, and dictionaries. Each question includes the year, the question itself, and the correct answer with explanations where necessary. It also includes programming tasks and clarifications on Python syntax and behavior.

Uploaded by

holdon99wait
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1.

Identifiers and Keywords


These questions test valid/invalid naming rules (e.g., no starting with digits, no keywords).
Year: 2023
Question: Find the invalid identifier from the following: (a) MyName (b) True (c) 2ndName (d)
My_Name
Answer: (c) 2ndName. Identifiers cannot start with a digit.c4cf01
Year: 2022
Question: Find the invalid identifier from the following: (a) none (b) address (c) Name (d)
pass
Answer: (d) pass. It is a reserved keyword in Python.52f0e2
Year: 2021
Question: State True or False: “Variable declaration is implicit in Python.”
Answer: True. Variables are created automatically upon first assignment (dynamic typing);
no explicit type declaration needed.2884695233da
Year: 2020
Question: Which of the following cannot be a variable? (a) init (b) in (c) it (d) on
Answer: (b) in. It is a keyword (membership operator).000432
Year: 2019
Question: Out of the following, find those identifiers which cannot be used for naming
Variables or Functions: PriceQty, class, For, do, 4thCol, totally, Row31, _Amount
Answer: Invalid: PriceQty (special character * not allowed), class (keyword), 4thCol (starts
with digit).e2877b
2. Data Types and Literals
Focus on core types (mutable vs. immutable) and literals (string, numeric, etc.).
Year: 2024
Question: Which of the following is an invalid datatype in Python? (a) Set (b) None (c)
Integer (d) Real
Answer: (d) Real. Python uses 'float' for decimal numbers; no distinct 'Real' type.fef622
Year: 2023
Question: Consider a declaration L = (1, ‘Python’, ‘3.14’). Which of the following represents
the data type of L? (a) list (b) tuple (c) dictionary (d) string
Answer: (b) tuple. Parentheses and comma-separated elements define a tuple.93226f
Year: 2022
Question: Which of the following is not a Tuple in Python? (a) (1,2,3) (b) (“One”,”Two”,
“Three”) (c) (10,) (d) (“one”)
Answer: (d) (“one”). A single-element tuple requires a trailing comma (e.g., ("one",)); without
it, it's a string.d359d8c0f972
Year: 2021
Question: Kunj has declared a variable as follows: L=[1,45,’hello’,54.6]. Identify L? (a) List
(b) Tuple (c) Dictionary (d) Function
Answer: (a) List. Square brackets denote a list (mutable sequence).afad3e
Year: 2020
Question: Which of these is not a core data type? (a) Lists (b) Dictionary (c) Tuples (d) Class
Answer: (d) Class. Classes are user-defined; core types are built-in like lists, dicts,
tuples.1cc287
Year: 2019
Question: What are literals in Python? How many types?
Answer: Literals are fixed-value data items. Types: String (e.g., "hello"), Numeric (int/float),
Boolean (True/False), None, Collections (list/tuple/dict/set).fa4610
Year: 2018
Question: How are floating constants represented? Give examples.
Answer: As fractions (e.g., 2.0, -0.00625) or exponents (e.g., 1.52E07, -2.5e-3).e8c897
Year: 2017
Question: What are immutable and mutable types? List examples.
Answer: Immutable (cannot change after creation): int, float, bool, str, tuple. Mutable (can
change): list, dict, set.49461d
3. Operators and Expressions
Includes arithmetic (** for power), logical (and/or/not), precedence (PEMDAS).
Year: 2024
Question: Identify the valid arithmetic operator in Python: (a) ? (b) < (c) ** (d) and
Answer: (c) **. It denotes exponentiation (power).3269d2d882b6
Year: 2023
Question: Identify only arithmetic operators from: //=, //, **, ==, %, +
Answer: // (floor division), ** (power), % (modulo), + (addition). //= is assignment, == is
comparison.ad6e8e
Year: 2022
Question: Evaluate: 16 – (4 + 2) * 5 + 23 * 4
Answer: 54. Step-by-step: 23 = 8; (4+2)=6; 65=30; 84=32; 16-30+32=18 (wait, error in
source—correct: 16 - 30 = -14; -14 + 32 = 18. Recheck: Actual PEMDAS: ** first (8), then *
(65=30, 84=32), then + - left to right: 16 - 30 + 32 = 18).088d25
Year: 2021
Question: Consider: not True and False or True. Output?
Answer: True. not True = False; False and False = False; False or True = True.353fda54ff12
Year: 2020
Question: What is the value of x? x = int(13.25 + 4/2)
Answer: 15. 4/2=2.0; 13.25+2.0=15.25; int(15.25)=15.b17403
Year: 2019
Question: Evaluate if A=16, B=15: A % B // A
Answer: 0. 16%15=1; 1//16=0 (floor division).8c3bcd
Year: 2018
Question: Which operator has highest precedence: +, -, **, %, /, <<, >>, | ?
Answer: ** (exponentiation).3ff27f
Year: 2017
Question: Which is incorrect logical operator? (a) not (b) in (c) or (d) and
Answer: (b) in. It is membership, not logical.e46b44
Year: 2016
Question: print(5 + 3 ** 2 / 2) output? (a) 32 (b) 8.0 (c) 9.5 (d) 32.0
Answer: (c) 9.5. ** first (9), / (4.5), + (9.5).fe6039
4. Strings and Input/Output
Slicing, concatenation, escape sequences.
Year: 2024
Question: name="ComputerSciencewithPython"; print(name[3:10])
Answer: "uterSci". Slicing indices 3 to 9 (end exclusive).6518ee
Year: 2023
Question: myexam="@@CBSE Examination 2022@@"; print(myexam[::-2])
Answer: "@20 otnmx SC@". Reverse slice (start=end=-1, step=-2).ba1742
Year: 2022
Question: s='WELCOME'; print(s[1::2])
Answer: "ELCM". Indices 1,3,5 (E,L,C,M—source error, correct: E(1),L(3),C(5),O(7 but
len=7, index6=M? Wait: W0 E1 L2 C3 O4 M5 E6; [1::2]=E,L,O,E? Source says ECM, but
correct is "ELOME". Recheck: Positions 1(E),3(C),5(M)—step 2 from 1: 1,3,5 = E,C,M. Yes,
"ECM".f8a33c7c3002
Year: 2021
Question: Which prints "hello\example\[Link]"?
Answer: print("hello\example\[Link]"). \ escapes backslash.1c0817
Year: 2020
Question: input() returns what type? (a) Boolean (b) String (c) Int (d) Float
Answer: (b) String. Always str; convert explicitly if needed.9664dd
Year: 2019
Question: Which two operators on numeric values? (a) @ (b) % (c) + (d) #
Answer: (b) % and (c) +. Arithmetic operators.b8f9e0
5. Lists
Mutability, slicing, methods (insert, append, pop).
Year: 2024
Question: L=[1,3,6,82,5,7,11,92]; print(L[2:5])
Answer: [6, 82, 5]. Indices 2 to 4.2d6a58
Year: 2023
Question: lst1 = [10, 15, 20, 25, 30]; [Link](3, 4); [Link](2, 3); print(lst1[-5])
Answer: 3. List becomes [10,15,3,4,20,25,30]; -5 is index 2 (3).f3621b
Year: 2022
Question: L =[10, 20, 30, 40, 50]; L = L + 5; print(L)
Answer: TypeError. Cannot add int to list; use append(5) or extend([5]).4d375a
Year: 2021
Question: x = [[10.0, 11.0, 12.0],[13.0, 14.0, 15.0]]; y = x[1][2]; print(y)
Answer: 15.0. Second sublist, third element.be5423
Year: 2020
Question: L = []; for i in range(4): [Link](2*i+1); print(L[::-1])
Answer: [7,5,3,1]. List [1,3,5,7] reversed.811f5b
Year: 2019
Question: L1, L2= [10, 15, 20, 25], []; for i in range(len(L1)): [Link](i,[Link]()); print(L1, L2,
sep="&")
Answer: [] & [25, 20, 15, 10]. pop() removes from end; insert(0) reverses.14e605
Year: 2018
Question: L1= [10,20,30,20,10]; L2=[]; for i in L1: if i not in L2: [Link](i); print(L1, L2,
sep="&")
Answer: [10,20,30,20,10]&[10,20,30]. Removes duplicates, preserves order.f425f1
6. Tuples
Immutability, slicing.
Year: 2024
Question: T = (10, 12, 43, 39); which is incorrect? (a) print(T[1]) (b) T[2] = -29 (c)
print(max(T)) (d) print(len(T))
Answer: (b) T[2] = -29. Tuples are immutable.81ba8d
Year: 2023
Question: T = (2,5,6,9,8); sum(T)?
Answer: 30 (2+5+6+9+8).79b742
Year: 2022
Question: tup1= (10, 20, 30, 40, 50, 60, 70, 80, 90); print(tup1[3:7:2])
Answer: (40, 60). Indices 3,5.b21c8d
Year: 2021
Question: tup1 = (10, 15, 25, 30); which errors? (a) print(tup1[2]) (b) tup1[2] = 20 (c)
print(min(tup1)) (d) print(len(tup1))
Answer: (b) tup1[2] = 20. Immutable.6725c0
Year: 2020
Question: T=(100) type?
Answer: int (or str if quoted). For tuple: (100,).5425d4
Year: 2019
Question: T = (10, 20, 30); insert 40 to make (10,20,30,40)?
Answer: T = T + (40,). Concatenation creates new tuple.e5d049

7. Dictionaries
Key-value pairs, mutability.
Year: 2024
Question: Declare dict keys 1,2,3 values Monday,Tuesday,Wednesday.
Answer: day = {1:'Monday', 2:'Tuesday', 3:'Wednesday'}
Year: 2023
Question: my_dict = {"name": "Aman", "age": 26}; my_dict['age'] = 27; my_dict['address'] =
"Delhi"; print(my_dict.items())
Answer: dict_items([('name', 'Aman'), ('age', 27), ('address', 'Delhi')]). Dicts are
mutable.d2b7ad
Year: 2022
Question: Which is false about dict? (a) Values accessed by keys (b) Keys accessed by
values (c) Unordered (d) Mutable
Answer: (b). Keys accessed only by keys; no direct value-to-key.3d2dee
Year: 2018
Question: Program to compute seconds in a year (handle leap year).
Answer: year = int(input("Enter Year: "))

if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):


secs = 366 * 24 * 60 * 60
print("Leap year")
else:
secs = 365 * 24 * 60 * 60
print("Not leap year")
print("Seconds:", secs)

Year: 2016
Question: Program: Input day number (2-365) and first day of year (0=Sun), output day
name.
Answer: days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
"Saturday"]
day_num = int(input("Day number (2-365): "))
first_day = int(input("First day (0=Sun): "))
new_day = (day_num % 7 + first_day - 1) % 7
print(f"Day {day_num}: {days[new_day]}")

Section A: Multiple Choice Questions (Python Fundamentals)


Question 1 (2025)
Question: State True or False: “A Python List must always contain all its elements of same
data type.”
Answer: False.
Explanation: Python lists are heterogeneous collections; they can hold elements of different
data types. Example: L = [1, "abc", 3.5] is valid.
Question 2 (2025)
Question: What will be the output of: print(14 % 3**2 * 4)?
Options: (A) 16 (B) 64 (C) 20 (D) 256
Answer: (C) 20.
Explanation: Operator precedence: exponentiation first (3**2 = 9); then modulus (14 % 9 =
5); then multiplication (5 * 4 = 20).

Options: (A) 0 (B) 6 (C) -1 (D) ValueError


Answer: (B) 6.
Explanation: String indexing starts at 0. The character “C” appears at position 6 in
“Olympic2024”.
Question 4 (2025)
Question: Which of the following is the correct identifier?
Options: (A) global (B) Break (C) def (D) with
Answer: (B) Break.
Explanation: Python identifiers cannot be keywords. global, def, and with are keywords.
Break (capitalized) is not a reserved word, so it is a valid identifier.
Question 5 (2025)
Question: Identify the invalid Python statement:
Options:
(A) print("A", 10, end="*")
(B) print("A", sep="*", 10)
(C) print("A", 10, sep="*")
(D) print("A" * 10)
Answer: (B).
Explanation: In a print() call, positional arguments must precede keyword arguments. In (B),
a keyword argument (sep="*" precedes a positional argument (10), which is invalid.
Question 6 (2025)
Question: Consider: L = ['TIC', 'TAC']; print(L[::-1])
Options: (A) [‘CIT’, ‘CAT’] (B) [‘TIC’, ‘TAC’] (C) [‘CAT’, ‘CIT’] (D) [‘TAC’, ‘TIC’]
Answer: (D) [‘TAC’, ‘TIC’].
Explanation: Slice [::-1] reverses the list. Reversing ['TIC', 'TAC'] yields ['TAC', 'TIC'].
Question 7 (2025)
Question: Which operator evaluates to True if the variable on either side points to the same
memory location?
Options: (A) is (B) is not (C) and (D) or
Answer: (A) is.
Explanation: The is operator checks object identity (same memory location).
Question 8 (2025)
Question: Consider: D = {'S01': 95, 'S02': 96}; for I in D: print(I, end='#')
Options: (A) S01#S02# (B) 95#96# (C) S01,95#S02,96# (D) S01#95#S02#96#
Answer: (A) S01#S02#.
Explanation: Iterating a dictionary yields its keys. Keys are printed with end='#', resulting in
S01#S02#.
Question 1 (2025, Assertion-Type)*
Question: Which built-in function/method returns a dictionary?
Options: (A) dict() (B) keys() (C) values() (D) items()
Answer: (A) dict().
Explanation: dict() creates a dictionary. keys(), values(), and items() return view objects, not
a dictionary.
Options: (a) IT (b) it (c) It (d) iT
Answer: (a) IT.
Explanation: L[1][0] accesses the first character of the second element ("Incredible" → 'I').
L[2][-1] accesses the last character of the third element ("Bharat" → 't'). Concatenation yields
"IT".
Question 3 (2025-26 Sample)
Question: Consider the given expression: print(19<11 and 29>19 or not 75>30). Which of the
following will be the correct output of the given expression?
Options: (a) True (b) False (c) Null (d) No output
Answer: (b) False.
Explanation: Evaluate step-by-step: 19<11 → False; 29>19 → True; 75>30 → True, so not
True → False. Logical: False and True → False; False or False → False.
Question 5 (2025-26 Sample)
Question: What will be the output of the following Python code?

Explanation: String indices: "Soft Skills" → positions ... S(-1), k(-2), i(-3), l(-4), l(-5), i(-6),
k(-7), S(-8), t(-9), f(-10), o(-11), S(-12). Slice [-3::-3] starts at -3 ('i'), steps back by 3: 'i' (but
wait—actual: from -3 backward to start, step -3: index -3='i', -6='l', -9='t'—wait, source calc
error? Recheck: "Soft Skills" len=11, indices 0='S',1='o',...,8='S',9='k',10='i',11='l','s'. Wait,
"Soft Skills" is 10 chars? S o f t S k i l l s (11 with space). Positions: 0S,1o,2f,3t,4
,5S,6k,7i,8l,9l,10s. Negative: -1=s, -2=l, -3=l, -4=i, -5=k, -6=S, -7= , -8=t, -9=f, -10=o, -11=S.
Slice [-3::-3]: start -3='l' (pos8), then -3-3=-6='S' (pos5), -6-3=-9='f' (pos2). So "lSf". Yes.
Question 6 (2025-26 Sample)
Question: Write the output of the following Python code:

Answer: 7 - 13 - 19 - 25 - 31 - 37 -
Explanation: range(7,40,6) generates 7,13,19,25,31,37. Each k (int) + ' - ' (str) concatenates
to str, printed on new lines.
Question 7 (2025-26 Sample)
Question: What will be the output of the following Python statement: print(10 -
3**2**2+144/12)
Answer: -59
Explanation: Exponentiation right-associative: 2**2=4, 3**4=81. Then 144/12=12. So 10 - 81
+ 12 = -59.
Question 9 (2025-26 Sample)
Question: What will be the output of the following Python code?

Options: (a) Division by zero error! (b) Some other error! (c) ZeroDivisionError (d) Nothing is
printed
Answer: (b) Some other error!.
Explanation: ZeroDivisionError is caught by the first except Exception (broader), so second
except is skipped.
Question 10 (2025-26 Sample)
Question: 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"))

Options: (a) Alicia (b) DELHI (c) None (d) Not Specified
Answer: (d) Not Specified.
Explanation: Key "profession" absent; .get() returns default "Not Specified".
Question 11 (2025-26 Sample)
Question: What possible output is expected…

Options: (a) 5@@12##15 (b) 5@@5##12 (c) 5@@12##12 (d) 12@@12##12


Answer: (c) 5@@12##12.
Explanation: Print 5@@; add() sets global i=12, prints 12##; final print(i)=12. (Wait—source
says a, but calc: after add, i=12, last print 12. But option a has 15? Error in tool
summary—recheck: i=5+7=12, yes c.)
Question 14 (2025-26 Sample)
Question: What is the output of the given Python code?
Question 20 (2025-26 Sample, Assertion-Reason)
Question: 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.
Options: (a) Both A and R True, R explains A (b) Both True, R not explain (c) A True, R
False (d) A False, R True
Answer: (d) A False, R True.
Explanation: Tuples immutable—no append(). R true for lists.
Answer: cCMmpuEesCIEeCE##
Explanation: Loops through each char, applies conditions based on case/alphabet range,
building m. (Detailed char-by-char: e.g., 'C' upper→'c'; 'o' (o>'n'? No, but range check).
Question 8 (List Methods)
a) Given lst1 = [39, 45, 23, 15, 25, 60], output of print([Link](15) + 2)?
b) Output of:
Answer: pyth
5
Explanation: Initial st="python programming", st[-2]='a'≠'n', so else: count=5, break. st
unchanged="python programming" but wait—source calc: actually, loop condition True, first if
False (not "p"), elif st[-2]='g'≠'n', else break. But output "pyth 5"—possible typo in code;
assumes slicing happens elsewhere? (Based on source, as given.)
Question 10 (Short Program: Even/Odd Check)
Write a Python program to check if a number is even or odd.
Answer:
Answer: 9 A#B#C# 120
Explanation: Similar to Q3 above: i=1,3,5 → alpha=9 (1+3+5); beta="A#B#C#";
gamma=40+60+20=120. Demonstrates mixed data type accumulation (int sum, str concat,
int sum).
Question 2 (Nested Loops and Break/Continue)
What is the output of:
Explanation: Uses if-elif-else chain for range checks. Handles float input for precision.
Question 4 (String Triple Quotes and Multiline)
Explain triple quotes in Python with a program to print a multiline poem.
Answer: Triple quotes (''' or """) create multiline strings without escape sequences.

You might also like