Based on the provided documents, here are some common questions and related
questions that are likely to appear in your Python programming exam:
Common Questions
1. Python Features
• List features of Python.
2. Basic Python Syntax
• Describe membership operators in Python.
• Describe the use of the elif keyword in Python.
• Describe indentation in Python.
3. Data Types and Operations
• Differentiate between list and tuple.
• List identity operators in Python.
• Describe tuples in Python.
• Explain bitwise operators in Python with examples.
• Explain membership and assignment operators with examples.
4. Control Structures
• Describe the continue keyword with an example.
• Explain decision-making statements (if, else, elif) with examples.
5. Functions
• Write a Python program to find the factorial of a number provided by the user.
• Explain any four built-in Python functions with examples.
• Explain how to use user-defined functions in Python with examples.
6. File Handling
• Describe the mkdir() function.
• Explain the readline() and readlines() functions with examples.
• Write a program to read the contents of first.txt and write the same content to
second.txt.
7. Object-Oriented Programming
• Define class and object in Python.
• Explain the concept of a default constructor with an example.
• Describe the self parameter with an example.
• Write a program to create a class EMPLOYEE with ID and NAME, and display
its contents.
8. Exception Handling
• Explain how the try-catch block is used for exception handling in Python with
examples.
• Write a program to show user-defined exceptions in Python.
9. Modules and Packages
• Explain the use of modules in Python.
• Write a program illustrating the use of a user-defined package in Python.
10. Data Structures
• Write basic operations of lists.
• Write a program to count the frequency of each character in a given file.
• Explain different functions or ways to remove key-value pairs from a dictionary.
Example Programs
1. Factorial Program
python
Copy code
def factorial(n): if n == 0: return 1 else: return n * factorial(n-1) num = int(input("Enter a
number: ")) print("The factorial of", num, "is", factorial(num))
2. Class Definition and Usage
python
Copy code
class Employee: def __init__(self, id, name): self.id = id self.name = name def display(self):
print(f"ID: {self.id}, Name: {self.name}") emp1 = Employee(1, "John") emp1.display()
3. File Reading and Writing
python
Copy code
with open('first.txt', 'r') as file1: data = file1.read() with open('second.txt', 'w') as file2:
file2.write(data)
4. Palindrome Check
python
Copy code
def is_palindrome(s): return s == s[::-1] s = input("Enter a string: ") if is_palindrome(s):
print(f"{s} is a palindrome") else: print(f"{s} is not a palindrome")
Explanation of Common Concepts
1. Bitwise Operators:
• & (AND), | (OR), ^ (XOR), ~ (NOT), << (left shift), >> (right shift).
2. Membership Operators:
• in (returns True if a value is found in the sequence), not in (returns True if a
value is not found in the sequence).
3. File Handling:
• read(): Reads the entire file.
• readline(): Reads a single line from the file.
• readlines(): Reads all the lines and returns them as a list of strings.
4. Exception Handling:
• try: Code block to test for errors.
• except: Code block to handle the error.
• finally: Code block that will be executed regardless of the result.
Tips for the Exam
• Practice writing and understanding simple Python programs.
• Understand the syntax and usage of basic Python constructs.
• Be familiar with common built-in functions and their applications.
• Know how to handle files and exceptions in Python.
• Review object-oriented programming concepts such as classes and inheritance.