Class 11 Python Revision Notes
1. Introduction to Python
- High-level, interpreted, and general-purpose programming language.
- Created by Guido van Rossum in 1991.
- Python is simple, readable, and has a large standard library.
2. Python Basics
- Print Statement: print("Hello World")
- Comments: Single line (#), Multi-line (''' ''')
- Input Function: input("Enter value: ")
3. Variables, Data Types and Operators
- Variables: No need to declare type. Eg: a = 5
- Data Types: int, float, str, bool
- Operators:
- Arithmetic: +, -, *, /, %, //, **
- Relational: ==, !=, >, <, >=, <=
- Logical: and, or, not
- Assignment: =, +=, -= etc.
4. Flow of Control
- Conditional Statements:
if condition:
# code
elif condition:
# code
else:
# code
- Loops:
- while loop:
while condition:
# code
- for loop:
for i in range(start, end, step):
# code
- Loop control: break, continue, pass
5. Strings
- Immutable
- String functions: len(), upper(), lower(), find(), replace(), split(), strip()
- Indexing and slicing: s[0], s[-1], s[0:5]
6. Lists
- Ordered and mutable
- Create list: lst = [1, 2, 3]
- List functions: append(), extend(), insert(), remove(), pop(), sort(), reverse()
- Indexing and slicing similar to strings
7. Tuples and Dictionaries
- Tuples: Immutable, defined using ()
- Example: t = (1, 2, 3)
- Dictionaries: Key-value pairs, defined using {}
- Example: d = {"name": "John", "age": 25}
- Access: d["name"]
- Functions: keys(), values(), items(), get(), update()
8. Functions
def function_name(parameters):
# code
return value
- Function calling: function_name(arguments)
- Default and keyword arguments
9. File Handling (Introduction)
- Open a file: f = open("file.txt", "r")
- Read: f.read(), f.readline(), f.readlines()
- Write: f.write("Hello")
- Close: f.close()