Python Learning Roadmap - Phase 1:
Python Basics
Introduction
Phase 1 is designed for absolute beginners who want to build a solid foundation in Python. It
covers basic concepts like variables, data types, operators, loops, functions, and more.
Lesson 1: Variables and Data Types
A variable is a name that refers to a value. It acts like a container for storing data values.
Python has several built-in data types including:
- int: Integer numbers (e.g., 10)
- float: Decimal numbers (e.g., 5.5)
- str: Strings or text (e.g., "Hello")
- bool: Boolean values (True or False)
Example:
name = "John"
age = 20
is_student = True
Lesson 2: Operators
Operators are used to perform operations on variables and values.
Types of operators:
- Arithmetic: +, -, *, /, %, **, //
- Comparison: ==, !=, >, <, >=, <=
- Logical: and, or, not
- Assignment: =, +=, -=, *=, etc.
Lesson 3: Conditional Statements
Conditional statements allow you to execute certain blocks of code based on conditions.
Syntax:
if condition:
# do something
elif condition:
# do something else
else:
# fallback
Lesson 4: Loops
Loops are used to repeat a block of code multiple times.
- for loop: Used to iterate over a sequence (like a list or range).
- while loop: Repeats as long as a condition is true.
Example:
for i in range(5):
print(i)
Lesson 5: Functions
A function is a block of reusable code that performs a specific task.
Syntax:
def function_name(parameters):
# code
return value
Example:
def greet(name):
return "Hello, " + name
Lesson 6: Lists, Tuples, Sets, Dictionaries
- List: Ordered and changeable. [1, 2, 3]
- Tuple: Ordered and unchangeable. (1, 2, 3)
- Set: Unordered, no duplicates. {1, 2, 3}
- Dictionary: Key-value pairs. {'name': 'John', 'age': 20}
Lesson 7: String Manipulation
Strings in Python can be manipulated using various methods like:
- len(), upper(), lower(), strip(), replace(), split(), join()
Example:
text = " Hello World "
print(text.strip().upper())
Lesson 8: Basic Input/Output
Use input() to get user input, and print() to display output.
Example:
name = input("Enter your name: ")
print("Hello", name)
Lesson 9: Exception Handling
Try-except blocks are used to handle errors gracefully.
Syntax:
try:
# risky code
except ExceptionType:
# handle error
Example:
try:
num = int(input("Enter a number: "))
except ValueError:
print("Invalid input")