Python Programming: Beginner
Comprehensive Question Bank
A curated collection of theoretical and practical exercises for Python novices.
Section 1: Python Fundamentals & History
Theory
1. Who created Python and in what year was it first released?
Theory
2. What does it mean when we say Python is an "Interpreted" language?
Theory
3. List five key features of Python that make it suitable for beginners.
Theory
4. Explain the difference between Python 2.x and Python 3.x. Why is Python 3
preferred today?
Theory
5. What is PEP 8 and why is it important for Python developers?
Section 2: Variables, Literals, and Identifiers
Theory
6. What are the rules for naming identifiers (variables) in Python?
Page 1
Practical
7. Identify which of the following variable names are invalid and why:
• 2my_var
• my-var
• _myvar
• my var
• class
Practical
8. Write a script to swap the values of two variables without using a third
temporary variable.
a = 5
b = 10
# Your code here
Section 3: Data Types - Numbers and Strings
Theory
9. Explain the difference between the 'int', 'float', and 'complex' data types.
Practical
10. Given the string s = "Python Programming", write the code to:
• Extract "Python" using slicing.
• Reverse the string.
• Count the occurrence of the letter 'r'.
Theory
11. What is string immutability? Demonstrate with an example of what
happens if you try to change a character in a string.
Page 2
Section 4: Operators and Expressions
Theory
12. Differentiate between / (division) and // (floor division) operators.
Practical
13. Predict the output of the following expression: 2 ** 3 ** 2. Explain the
order of operations.
Theory
14. What are Membership Operators and Identity Operators? Provide
examples for in and is.
Section 5: Control Flow - Conditional Statements
Practical
15. Write a program that takes an integer input and checks if it is even or
odd.
Practical
16. Create a simple grading system:
• 90-100: A
• 80-89: B
• 70-79: C
• Below 70: Fail
Section 6: Control Flow - Loops
Theory
Page 3
17. Explain the difference between a for loop and a while loop. When would
you use one over the other?
Practical
18. Write a program to print the Fibonacci sequence up to the 10th term using
a loop.
Practical
19. Use a nested loop to print the following pattern:
*
**
***
****
*****
Theory
20. What is the purpose of break, continue, and pass statements?
Section 7: Lists and Tuples
Theory
21. Compare Lists and Tuples. Why would you use a Tuple instead of a List?
Practical
22. Write a program to find the largest and smallest element in a list without
using built-in max() and min().
Practical
23. How do you remove duplicates from a list? (Hint: Consider using another
data type).
Page 4
Section 8: Dictionaries and Sets
Theory
24. What is a dictionary in Python? How does it differ from a list?
Practical
25. Create a dictionary of 5 students and their marks. Write code to find the
student with the highest marks.
Theory
26. What are the characteristics of a Set? Explain with examples of union and
intersection.
Section 9: Functions
Theory
27. Define a function. What is the difference between a parameter and an
argument?
Theory
28. What are *args and **kwargs in Python functions? Give an example of
their usage.
Practical
29. Write a recursive function to calculate the factorial of a number.
Theory
30. What is a lambda function? Write a lambda function that squares a
number.
Page 5
Section 10: File Handling
Theory
31. Name the different modes for opening a file in Python (r, w, a, r+, etc.) and
explain each.
Practical
32. Write a program to read a text file and count the number of words in it.
Theory
33. Why is it recommended to use the with statement when opening files?
Section 11: Exception Handling
Theory
34. What is the purpose of try...except...finally blocks?
Practical
35. Write a program that asks for two numbers and divides them, handling
the ZeroDivisionError and ValueError.
Section 12: Modules and Packages
Theory
36. What is the difference between a module and a package?
Practical
37. How do you import only a specific function from a module? Give an
example using the math module.
Page 6
Section 13: List Comprehensions
Theory
38. What is List Comprehension? How does it improve code readability?
Practical
39. Use list comprehension to create a list of squares for all even numbers
between 1 and 20.
Section 14: Built-in Functions
Practical
40. Explain the usage of map(), filter(), and reduce() with examples.
Theory
41. What does the enumerate() function do? Show an example of looping
through a list with its index.
Section 15: Input and Output
Practical
42. How do you format output using f-strings (available in Python 3.6+)? Give
an example.
Practical
43. Write a program that accepts a comma-separated sequence of numbers
from the user and generates a list and a tuple containing those numbers.
Section 16: Basic Object-Oriented Programming (OOP)
Theory
Page 7
44. Define 'Class' and 'Object' with a real-world analogy.
Theory
45. What is the __init__ method in Python? What is its purpose?
Practical
46. Create a class Rectangle with attributes length and width. Add a method
area() to calculate the area.
Theory
47. What is Inheritance? Briefly explain with a simple example (e.g., Animal ->
Dog).
Section 17: Date and Time
Practical
48. Write a Python script to display the current date and time in the format:
YYYY-MM-DD HH:MM:SS.
Section 18: Advanced Beginner Logic Challenges
Practical
49. Write a function to check if a given string is a Palindrome (reads the same
forwards and backwards).
Practical
50. Write a program that prints numbers from 1 to 100. For multiples of 3
print "Fizz", for multiples of 5 print "Buzz", and for multiples of both print
"FizzBuzz".
Page 8
Section 19: Comprehensive Review - Coding Exercises
The following questions require writing full scripts to solve specific problems.
Practical Exercise 51
Write a program that takes a sentence from the user and counts the number
of uppercase and lowercase letters.
Practical Exercise 52
Implement a basic calculator that can perform Addition, Subtraction,
Multiplication, and Division based on user input.
Practical Exercise 53
Generate a list of prime numbers between 1 and 50 using a function.
Practical Exercise 54
Write a script to sort a list of dictionaries based on a specific key (e.g., sort
students by age).
Practical Exercise 55
Write a program to find the sum of all elements in a nested list (e.g., [[1,2],
[3,4], [5]]).
Page 9
Section 20: Python Mock Test (Theoretical Part)
Attempt these questions to test your conceptual clarity.
Q1. Is Python case sensitive when dealing with identifiers?
Q2. What is the output of print(type(1/2)) in Python 3?
Q3. Which of the following is an invalid variable name? (a) _var (b) var_1 (c)
1_var (d) Var
Q4. How do you insert multiline comments in Python?
Q5. What is the difference between range(5) and list(range(5))?
Page 10
Section 21: Additional Practical Challenges (Set A)
Exercise 56
Write a program to convert Celsius to Fahrenheit and vice versa based on
user choice.
Exercise 57
Write a script to check if a year is a leap year.
Exercise 58
Develop a simple 'Guess the Number' game where the computer selects a
random number and the user tries to guess it with hints (Higher/Lower).
Page 11
Section 22: Additional Practical Challenges (Set B)
Exercise 59
Write a program to remove all whitespace characters from a given string.
Exercise 60
Write a program to find the intersection of two lists.
Page 12
Section 23: Additional Practical Challenges (Set C)
Exercise 61
Write a program to flatten a deep nested list.
Exercise 62
Write a program to count the frequency of each word in a given paragraph.
Page 13
Section 24: Python Standard Library Exploration
Theory
Q63. What is the os module used for? List 3 common functions.
Theory
Q64. What is the random module? How do you pick a random element from a
list?
Page 14
Section 25: Common Coding Patterns
Exercise 65
Implement a Linear Search algorithm.
Exercise 66
Implement a Bubble Sort algorithm.
Page 15
Section 26: Debugging and Documentation
Theory
Q67. What are 'Docstrings' and how are they used in Python?
Theory
Q68. Explain the difference between Syntax Errors, Runtime Errors, and
Logical Errors.
Page 16
Section 27: Final Challenge
Exercise 69
Build a simple Contact Book application where users can Add, View, and
Delete contacts. The contacts should be stored in a file.
Theory
Q70. Define the concept of 'Mutables' vs 'Immutables' in Python. List two
examples for each.
-- End of Question Bank --
Page 17