Class 12 Python – Revision Notes (No Equations)
1. Basics of Python
-
Python is a high-level, interpreted programming language.
-
Case-sensitive:
Variableandvariableare different. -
Supports dynamic typing, meaning variables can store any data type.
-
Indentation is important – it defines blocks of code.
2. Data Types
-
Numeric types: int, float, complex
-
Sequence types: list, tuple, string
-
Set types: set, frozenset
-
Mapping type: dictionary (key-value pairs)
-
Boolean: True or False
-
None: represents absence of value
3. Variables and Constants
-
Variables store data values.
-
Constants are fixed values that do not change.
-
Python does not require explicit declaration; just assign a value.
4. Operators in Python
-
Arithmetic operators: +, -, *, /, %, //, **
-
Comparison operators: ==, !=, >, <, >=, <=
-
Logical operators: and, or, not
-
Assignment operators: =, +=, -=, *=, /=
-
Membership operators: in, not in
-
Identity operators: is, is not
5. Control Structures
-
Conditional statements:
-
if,elif,else– used for decision making
-
-
Loops:
-
forloop – iterate over sequences -
whileloop – execute until a condition is False
-
-
Break and continue:
-
break– exits the loop immediately -
continue– skips the current iteration
-
6. Functions
-
Functions group reusable code for modular programming.
-
Defining a function: Use
defkeyword. -
Calling a function: Use the function name followed by parentheses.
-
Functions can return values or perform actions without returning.
-
Arguments/Parameters: Inputs passed to functions.
7. Strings and String Operations
-
Strings are sequences of characters enclosed in quotes.
-
Can perform operations like:
-
Concatenation: joining strings
-
Repetition: repeating strings multiple times
-
Indexing: accessing individual characters
-
Slicing: extracting substrings
-
-
Strings are immutable – cannot be changed once created.
8. Lists and Tuples
-
List: Ordered, mutable collection of items
-
Tuple: Ordered, immutable collection of items
-
Operations include: adding, removing, updating elements (for lists), accessing elements using indexing and slicing
9. Dictionary and Sets
-
Dictionary: Collection of key-value pairs; keys are unique
-
Set: Unordered collection of unique elements
-
Operations on sets: union, intersection, difference, membership check
10. File Handling
-
Opening files: in read, write, append modes
-
Reading files: read entire content or line by line
-
Writing files: write or append data to a file
-
Closing files: release the resource after use
11. Exception Handling
-
Python uses try-except blocks to handle errors.
-
Try block: contains code that may raise an exception
-
Except block: handles the exception gracefully
-
Prevents program crashes due to runtime errors
12. Object-Oriented Programming (OOP)
-
Class: Blueprint for creating objects
-
Object: Instance of a class
-
Attributes: Properties of an object
-
Methods: Functions defined inside a class
-
Encapsulation: Keeping data safe inside objects
-
Inheritance: A class can derive properties from another class
-
Polymorphism: Same method can behave differently in different classes
13. Modules and Libraries
-
Module: File containing Python code (functions, classes)
-
Importing modules: Allows reuse of code
-
Common libraries:
-
math– mathematical operations -
random– generate random numbers -
os– interact with the operating system -
datetime– work with dates and times
-
14. Recap for Revision
-
Python is high-level and dynamic
-
Key concepts: variables, data types, control structures
-
Important data structures: list, tuple, dictionary, set
-
Modular programming: functions and modules
-
File handling and exception handling
-
Object-Oriented Programming: class, object, inheritance, polymorphism
0