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

Python Exam Oriented Notes

Python basic

Uploaded by

19Khadeeja Nahas
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 views11 pages

Python Exam Oriented Notes

Python basic

Uploaded by

19Khadeeja Nahas
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

Python Exam-Oriented Notes

Unit 1 – Introduction to Python


Python is a high-level, interpreted, object-oriented programming language.
Features: Simple, Open Source, Portable, Extensible, Large Library Support.
Sample Program:

print("Hello, Python!")
Unit 2 – Basics of Python
Variables: Used to store data. Example: x = 10
Data Types: int, float, str, bool, list, tuple, dict, set.
Operators: Arithmetic (+, -), Relational (>, <), Logical (and, or, not).
Input/Output: input() & print().
Unit 3 – Control Statements
Decision Making: if, elif, else.
Loops: for, while.
Jump Statements: break, continue, pass.
Unit 4 – Functions & Modules
Defining Functions: def add(a,b): return a+b
Default & Keyword Arguments.
Lambda Functions: sum = lambda x,y: x+y
Modules: import math, random.
Unit 5 – Data Structures
List: Mutable sequence. Example: nums = [1,2,3]
Tuple: Immutable sequence. Example: tup = (1,2,3)
Set: Unordered unique collection. Example: s = {1,2,3}
Dictionary: Key-value pairs. Example: d = {'a':1,'b':2}
List Comprehension: [x**2 for x in range(5)]
String Handling: s = 'Python'; [Link](), [Link](), s[::-1]
Unit 6 – Exception Handling
try-except-finally block handles errors gracefully.
Example:
try:
x=1/0
except ZeroDivisionError:
print("Error")
raise: Used to raise exceptions manually.
Unit 7 – File Handling
Open a File: f = open('[Link]','r')
Read & Write: [Link](), [Link]('text')
Close File: [Link]()
With Statement: with open('[Link]') as f: data = [Link]()
Unit 8 – Object-Oriented Programming
Class & Object: class Car: pass; obj = Car()
Constructor: def __init__(self): [Link]='BMW'
Inheritance: class B(A): pass
Polymorphism: Method Overriding.
Encapsulation: Hiding data using private variables (_var).
Abstraction: Using ABC module for abstract classes.
Unit 9 – Python Libraries
NumPy: Array operations. Example: import numpy as np; [Link]([1,2,3])
Pandas: DataFrames & Series. Example: import pandas as pd; [Link]()
Matplotlib: Visualization. Example: import [Link] as plt; [Link]([1,2,3])
Unit 10 – Important Programs
Factorial:
def fact(n): return 1 if n==0 else n*fact(n-1)
Fibonacci:
a,b=0,1
for i in range(5): print(a); a,b=b,a+b
Palindrome:
s='madam'; print(s==s[::-1])
Prime Check:
for i in range(2,n): if n%i==0: print('Not Prime')
Unit 11 – Quick Revision Questions
Q1. What are Python's key features?
Q2. Difference between list, tuple, set, dict?
Q3. What is the difference between == and is?
Q4. Explain global & local variables.

You might also like