Python Notes for Class 11 and 12 CBSE
Introduction to Python
- Python is a high-level, interpreted programming language with simple syntax and powerful
libraries.
Python Basics
Variables and Data Types
- Variables store data values.
- int: Integer values (e.g., 10).
- float: Floating-point values (e.g., 10.5).
- str: String values (e.g., "Hello").
- bool: Boolean values (True or False).
- list: Ordered collection (e.g., [1, 2, 3]).
- tuple: Immutable ordered collection (e.g., (1, 2, 3)).
Python Notes for Class 11 and 12 CBSE
- dict: Key-value pairs (e.g., {"name": "John", "age": 25}).
Operators
- Arithmetic Operators: Perform mathematical operations (+, -, *, /, %, //, **).
- Comparison Operators: Compare values (==, !=, >, <, >=, <=).
- Logical Operators: Combine conditional statements (and, or, not).
Input and Output
- input(): Gets input from the user.
- print(): Displays output to the console.
Control Structures
Conditional Statements
Python Notes for Class 11 and 12 CBSE
- if: Executes a block of code if the condition is true.
- if-else: Executes one block of code if the condition is true, another if false.
- if-elif-else: Checks multiple conditions.
Loops
- for: Iterates over a sequence.
- while: Repeats as long as the condition is true.
- break: Exits the loop.
- continue: Skips the current iteration.
Functions
- def: Defines a function.
- return: Sends back a result from a function.
Python Notes for Class 11 and 12 CBSE
Object-Oriented Programming (OOP)
Classes and Objects
- class: Blueprint for creating objects.
- __init__(): Constructor method, initializes attributes.
Modules and Packages
- import: Includes external Python files.
Exception Handling
- try-except: Catches and handles errors.
File Handling
Python Notes for Class 11 and 12 CBSE
- open(): Opens a file.
- read()/write(): Reads from or writes to a file.
- close(): Closes the file.
Python Libraries
- NumPy: Numerical computations.
- Pandas: Data manipulation.
- Matplotlib: Data visualization.
CBSE Specific Topics
Strings
- Concatenation, slicing, indexing.
- Methods: lower(), upper(), find(), replace(), split(), join().
Python Notes for Class 11 and 12 CBSE
Lists
- Methods: append(), insert(), remove(), pop(), sort(), reverse().
Dictionaries
- Methods: keys(), values(), items(), get().
Data Visualization
- Using Matplotlib for plots.
Data Handling
- Reading CSV files with Pandas.