0% found this document useful (0 votes)
4 views

Python Exam Important Points Sheet

The document outlines important points for a Python exam, covering basic concepts, control flow, functions, data structures, exception handling, and object-oriented programming (OOP). It emphasizes key topics such as classes, encapsulation, inheritance, and common libraries, along with exam tips for effective preparation. Additionally, it provides a detailed explanation of OOP concepts, including classes, objects, encapsulation, and types of inheritance.

Uploaded by

deepgupta.iimun
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Python Exam Important Points Sheet

The document outlines important points for a Python exam, covering basic concepts, control flow, functions, data structures, exception handling, and object-oriented programming (OOP). It emphasizes key topics such as classes, encapsulation, inheritance, and common libraries, along with exam tips for effective preparation. Additionally, it provides a detailed explanation of OOP concepts, including classes, objects, encapsulation, and types of inheritance.

Uploaded by

deepgupta.iimun
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Python Exam Important Points Sheet

1. Basic Python Concepts

• Variables & Data Types: int, float, str, bool, list, tuple, dict, set

• Type Checking: type(variable)

• Type Casting: int(x), float(x), str(x)

• Operators: +, -, *, /, //, %, **, and, or, not

2. Control Flow

• If-Else Conditionals:

• if x > 10:

• print("Greater")

• elif x == 10:

• print("Equal")

• else:

• print("Smaller")

• Loops:

o for x in range(n): (Loop over range)

o for key, value in dict.items(): (Dictionary iteration)

o while condition: (Loop until condition is false)

o break, continue

3. Functions

• Defining a Function:

• def add(a, b):

• return a + b

• Lambda Function: square = lambda x: x*x

• Default Arguments: def greet(name="Guest"):

4. Data Structures

• Lists:

o Mutable, ordered: [1, 2, 3]

o Methods: .append(), .pop(), .sort()

• Tuples:

o Immutable, ordered: (1, 2, 3)


• Dictionaries:

o Key-value pairs: {'name': 'Alice', 'age': 25}

o Methods: .keys(), .values(), .items()

• Sets:

o Unordered, unique values: {1, 2, 3}

o Operations: union(), intersection()

5. Exception Handling

• Try-Except:

• try:

• x = 10 / 0

• except ZeroDivisionError:

• print("Cannot divide by zero!")

6. Object-Oriented Programming (OOP)

• Class & Object:

• class Car:

• def __init__(self, brand):

• self.brand = brand

• my_car = Car("Toyota")

• Encapsulation: Private variables _var, __var

• Inheritance:

• class ElectricCar(Car):

• def __init__(self, brand, battery):

• super().__init__(brand)

• self.battery = battery

• Polymorphism:

o Method Overriding in subclasses

7. Modules & Libraries

• Importing Modules:

• import math

• print(math.sqrt(16))

• Common Libraries:
o NumPy: import numpy as np

o Pandas: import pandas as pd

o Flask (Web Dev): from flask import Flask

8. Miscellaneous

• List Comprehension:

• squares = [x**2 for x in range(10)]

• File Handling:

• with open("file.txt", "r") as f:

• data = f.read()

• Decorator Example:

• def decorator(func):

• def wrapper():

• print("Before function execution")

• func()

• return wrapper

Exam Tips:

• Focus on syntax and commonly used functions.

• Practice writing short code snippets.

• Revise OOP concepts thoroughly.

• Understand error handling and debugging.

• Be familiar with list/dict comprehensions.

• Time management: Don't spend too long on one question!

Object-Oriented Programming (OOP) Concepts in Python

OOP is a programming paradigm that organizes code into objects, which group data and behavior
together. The main concepts are:

1. Classes and Objects

• 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:

o Public: Accessible from anywhere.

o Protected (_var): Meant for internal use but still accessible.

o Private (__var): Cannot be accessed directly from outside the class.

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.

2. Multiple Inheritance – A child class inherits from multiple parent classes.

3. Multilevel Inheritance – A child class inherits from a parent class, which itself
inherits from another parent.

4. Hierarchical Inheritance – Multiple child classes inherit from a single parent.

Why use it?


Inheritance avoids code duplication, making programs easier to maintain and extend.

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.

You might also like