Python Exam Important Points Sheet
Python Exam Important Points Sheet
• Variables & Data Types: int, float, str, bool, list, tuple, dict, set
2. Control Flow
• If-Else Conditionals:
• if x > 10:
• print("Greater")
• elif x == 10:
• print("Equal")
• else:
• print("Smaller")
• Loops:
o break, continue
3. Functions
• Defining a Function:
• return a + b
4. Data Structures
• Lists:
• Tuples:
• Sets:
5. Exception Handling
• Try-Except:
• try:
• x = 10 / 0
• except ZeroDivisionError:
• class Car:
• self.brand = brand
• my_car = Car("Toyota")
• Inheritance:
• class ElectricCar(Car):
• super().__init__(brand)
• self.battery = battery
• Polymorphism:
• Importing Modules:
• import math
• print(math.sqrt(16))
• Common Libraries:
o NumPy: import numpy as np
8. Miscellaneous
• List Comprehension:
• File Handling:
• data = f.read()
• Decorator Example:
• def decorator(func):
• def wrapper():
• func()
• return wrapper
Exam Tips:
OOP is a programming paradigm that organizes code into objects, which group data and behavior
together. The main concepts are:
• Class: A blueprint for creating objects. It defines attributes (variables) and methods
(functions) that describe an object.
• Object: An instance of a class that has its own data but follows the class structure.
Example Analogy:
A "Car" class can define attributes like brand and model, and behaviors like start() and stop(). An
object of this class would be a specific car, such as a Toyota Corolla.
2. Encapsulation
• Definition: The concept of restricting direct access to certain details of an object and
controlling interactions through methods.
• Access Modifiers:
Why is it useful?
Encapsulation protects data integrity and prevents unintended modifications by enforcing controlled
access.
3. Inheritance
• Definition: A mechanism where a child class derives attributes and methods from a parent
class, promoting code reuse.
• Types of Inheritance:
1. Single Inheritance – One child class inherits from one parent class.
3. Multilevel Inheritance – A child class inherits from a parent class, which itself
inherits from another parent.
Example Analogy:
A Vehicle class may define general attributes like speed and fuel, while Car and Bike classes inherit
from Vehicle, adding their specific behaviors.