0% found this document useful (0 votes)
15 views4 pages

Python Revision Sheet

This document serves as a Python revision sheet covering key concepts such as variables, data types, control statements, functions, data structures, file handling, exception handling, and object-oriented programming. It includes examples for each topic, demonstrating the syntax and usage of Python features. Advanced OOP concepts like static methods, class methods, operator overloading, magic methods, abstract classes, and multiple inheritance are also discussed.

Uploaded by

Aditya Katkhede
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views4 pages

Python Revision Sheet

This document serves as a Python revision sheet covering key concepts such as variables, data types, control statements, functions, data structures, file handling, exception handling, and object-oriented programming. It includes examples for each topic, demonstrating the syntax and usage of Python features. Advanced OOP concepts like static methods, class methods, operator overloading, magic methods, abstract classes, and multiple inheritance are also discussed.

Uploaded by

Aditya Katkhede
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

PYTHON REVISION SHEET

1. VARIABLES AND DATA TYPES

---------------------------

Variables are used to store data values.

Python is dynamically typed.

Examples:

x = 10 # Integer

y = 3.14 # Float

name = "Aditya" # String

is_active = True # Boolean

list1 = [1, 2, 3]

tuple1 = (1, 2, 3)

set1 = {1, 2, 3}

dict1 = {'a': 1, 'b': 2}

2. CONTROL STATEMENTS

---------------------

Conditional Statements:

if, elif, else

Loops:

for i in range(5): print(i)

while condition:

# code

break exits loop

continue skips to next iteration

pass does nothing

3. FUNCTIONS

------------

def greet(name):
return "Hello " + name

Default Args:

def add(x, y=0): return x + y

*args and **kwargs:

def func(*args, **kwargs): pass

Lambda:

f = lambda x: x + 2

4. DATA STRUCTURES

-------------------

List Ordered, mutable

list1 = [1, 2, 3]

Tuple Ordered, immutable

tuple1 = (1, 2, 3)

Set Unordered, no duplicates

set1 = {1, 2, 3}

Dict Key-value pairs

dict1 = {"a": 1, "b": 2}

List Comprehension:

[x**2 for x in range(5)]

5. FILE HANDLING

----------------

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

print(f.read())
Modes: r, w, a, r+

6. EXCEPTION HANDLING

---------------------

try:

x = 10 / 0

except ZeroDivisionError:

print("Cannot divide by zero")

finally:

print("Always runs")

7. OBJECT ORIENTED PROGRAMMING

------------------------------

class Car:

def __init__(self, model):

self.model = model

def drive(self):

print(f"{self.model} is driving")

mycar = Car("Toyota")

mycar.drive()

Encapsulation Hiding data using private variables

Polymorphism Same method name, different behavior

Inheritance Deriving class from another class

class ElectricCar(Car):

def drive(self):

print(f"{self.model} runs on electricity")

8. ADVANCED OOPs CONCEPTS

--------------------------

Static Method:

@staticmethod
def util(): print("Utility")

Class Method:

@classmethod

def create(cls): return cls()

Operator Overloading:

class Point:

def __init__(self, x): self.x = x

def __add__(self, other): return Point(self.x + other.x)

Magic Methods:

__init__, __str__, __len__, __add__, __eq__, etc.

Abstract Classes:

from abc import ABC, abstractmethod

class Shape(ABC):

@abstractmethod

def area(self): pass

Multiple Inheritance:

class A: pass

class B: pass

class C(A, B): pass

You might also like