1.
Environment Setup
Tasks:
● Install Python
○ Download from python.org
○ Enable “Add Python to PATH” during installation.
Verify installation:
python --version
○
● Install VS Code
○ Download from code.visualstudio.com.
○ Install the Python extension for syntax highlighting and
debugging.
● Install PyCharm (Community Edition)
○ Download from JetBrains.
○ Create a new Python project and configure the interpreter.
2. First Python Program
Task:
Write and execute a simple program:
print("Hello World")
Run in Terminal:
python hello.py
●
3. Basic Operations & Debugging
Tasks:
Arithmetic Operations:
x = 10
y = 20
print(x + y) # Addition (30)
print(x - y) # Subtraction (-10)
print(x * y) # Multiplication (200)
print(x / y) # Division (0.5)
●
● Debugging in PyCharm/VS Code:
1. Set breakpoints by clicking the gutter.
2. Use Step Over (F8) to execute line-by-line.
4. Comments & Best Practices
Tasks:
Single-line Comment:
# This is a comment
Multi-line Comment:
"""
This is a multi-line
comment (docstring).
"""
5. Variables & Naming Conventions
Rules:
● Use lower_case_with_underscores (PEP 8 standard).
● Avoid reserved keywords (if, for, class).
● Start with a letter or _, not a number.
Example:
total_cost = 100 # Descriptive name
student_age = 20 # Lowercase with underscore
_is_admin = True # Private variable (convention)
6. Data Types
(A) Numeric Types
● Integer (int): age = 25
● Float (float): height = 5.9
● Complex (complex): z = 2 + 3j
(B) Sequence Types
List (Mutable):
fruits = ["apple", "banana", "cherry"]
fruits[0] = "orange" # Modifiable
Tuple (Immutable):
colors = ("red", "green", "blue")
# colors[0] = "yellow" # Error (immutable)
Range:
numbers = range(1, 10, 2) # 1, 3, 5, 7, 9
●
© Mapping Type
Dictionary (dict):
person = {
"name": "Rabbi",
"age": 34,
"is_bangladeshi": True
}
print(person["name"]) # Access value
(D) Set Types
Set (Mutable, Unique):
unique_numbers = {1, 2, 2, 3} # {1, 2, 3}
FrozenSet (Immutable):
frozen = frozenset({1, 2, 3})
(E) Boolean & None
● is_student = True
● has_money = None # Absence of value
7. Type Checking & Conversion
Tasks:
Check Type:
print(type(10)) # <class 'int'="">
print(type("Hello")) # <class 'str'="">
●
Explicit Conversion:
num_str = "123"
num_int = int(num_str) # String → Integer
Implicit Conversion:
x = 10 # int
y = 3.14 # float
z = x + y # float (13.14)
8. Mutability vs Immutability
Immutable Objects:
Cannot be modified after creation (int, str, tuple).
a = 10
print(id(a)) # Memory address (unchanged if reassigned)
Mutable Objects:
Can be modified (list, dict, set).
my_list = [1, 2, 3]
my_list[0] = 100 # Valid (same memory address)
●
9. Exception Handling
Task: Handle type conversion errors.
try:
num = int("abc") # Fails (ValueError)
except ValueError as e:
print(f"Error: {e}") # Error: invalid literal for int()
10. Key Concepts Summary
Topic Key Notes
Variables Use descriptive names
(total_cost).
Data Types Know mutability (lists vs
tuples).
Type Explicit (int()) vs implicit (x
Conversion + y).
Debugging Use breakpoints and step
execution.
Comments # for single-line, """ for
multi-line.