Complete Python Notes
1. Introduction to Python
Python is a high-level, interpreted programming language known for its simplicity.
Example:
print('Hello, World!')
2. Variables and Data Types
Variables are used to store data.
Data types include: int, float, str, bool, list, tuple, set, dict.
Example:
x = 10
name = 'Alice'
is_happy = True
3. Operators
Operators perform operations on variables.
Types: Arithmetic (+, -, *, /), Comparison (==, !=), Logical (and, or, not).
Example:
result = 5 + 3
print(result > 6 and result < 10)
4. Conditional Statements
if, elif, and else are used to perform decisions.
Example:
age = 18
if age >= 18:
print('Adult')
else:
print('Minor')
Complete Python Notes
5. Loops
Used to repeat a block of code.
for loop and while loop are common.
Example:
for i in range(5):
print(i)
count = 0
while count < 5:
print(count)
count += 1
6. Functions
Functions are blocks of reusable code.
Example:
def greet(name):
print('Hello,', name)
greet('Alice')
7. Lists and Tuples
List: Mutable, Tuple: Immutable.
Example:
my_list = [1, 2, 3]
my_tuple = (1, 2, 3)
print(my_list[0])
8. Dictionaries
Dictionaries store data in key-value pairs.
Example:
Complete Python Notes
person = {'name': 'Bob', 'age': 25}
print(person['name'])
9. File Handling
Used to read/write files.
Example:
with open('file.txt', 'w') as f:
f.write('Hello file')
10. Object-Oriented Programming
Python supports OOP with classes and objects.
Example:
class Person:
def __init__(self, name):
self.name = name
def greet(self):
print('Hello', self.name)
p = Person('Alice')
p.greet()