Python Question Bank – Answer Sheet
Unit 1: Introduction and Syntax
1. Features of Python
• Simple & Readable: Easy syntax similar to English.
• Interpreted Language: No compilation required.
• Object-Oriented: Supports OOP concepts.
• Portable: Runs on multiple platforms.
• Large Library Support: Extensive standard libraries.
2. Input and Output Functions
name = input("Enter name: ")
print("Hello", name)
• input() → takes user input (string by default)
• print() → displays output
3. Keywords and Identifiers
• Keywords: Reserved words (e.g., if, else, for, while)
• Identifiers: Names of variables/functions
x = 10 # valid identifier
4. Data Types in Python
• Number: int, float
• String: "hello"
• List: [1,2,3]
• Tuple: (1,2,3)
• Set: {1,2,3}
• Dictionary: {"a":1}
5. Type Casting
x = "10"
y = int(x) # convert to integer
Unit 2: Operators and Control Flow
6. break, continue, pass
for i in range(5):
if i == 3:
break
• break → exit loop
• continue → skip iteration
• pass → do nothing
7. Python Operators
• Arithmetic: + - * /
• Comparison: == != >
• Logical: and or not
print(5 > 3) # True
8. Operator Precedence
• Order of execution (BODMAS rule)
print(2 + 3 * 4) # 14
9. Even or Odd Program
num = int(input("Enter number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
10. Logical & Comparison Operators
• Logical: and, or, not
• Comparison: ==, !=, >, <
print(5 > 3 and 2 < 4)
11. for Loop (1 to 10)
for i in range(1, 11):
print(i)
12. while Loop (First 10 Natural Numbers)
i=1
while i <= 10:
print(i)
i += 1
13. Pattern Program
for i in range(1, 6):
print("* " * i)
14. Largest Among Three Numbers
a, b, c = 10, 20, 15
if a > b and a > c:
print("a is largest")
elif b > c:
print("b is largest")
else:
print("c is largest")
15. Difference: while vs for
Feature for loop while loop
Use Known iterations Unknown iterations
Syntax Simple Condition-based
16. Membership & Identity Operators
x = [1,2,3]
print(2 in x) # True
print(x is x) # True
Unit 3: Data Structures
16. Tuple vs List
Feature List Tuple
Mutable Yes No
Syntax [] ()
17. Set Operations
a = {1,2,3}
b = {3,4,5}
print(a | b) # union
print(a & b) # intersection
18. List Operations Program
lst = [1,2,3]
[Link](4)
[Link](2)
print(len(lst))
19. Dictionary Add & Modify
d = {"a":1}
d["b"] = 2 # add
d["a"] = 10 # modify
20. Basic List Operations
• Append: [Link]()
• Remove: [Link]()
• Access: list[index]
21. Remove Duplicates Using Set
lst = [1,2,2,3]
lst = list(set(lst))
print(lst)
22. Tuple Operations
t = (1,2,3)
print(t[0])
print(len(t))
23. Dictionary Operations
d = {"a":1, "b":2}
print(d["a"]) # access
d["c"] = 3 # add
del d["b"] # delete
24. Merge Two Dictionaries
d1 = {"a":1}
d2 = {"b":2}
[Link](d2)
print(d1)
25. Difference: Set vs List
Feature List Set
Order Ordered Unordered
Duplicate Allowed Not allowed
26. Dictionary Program
d = {"a":1}
d["b"] = 2
del d["a"]
print(d)