Below is a comprehensive Python tutorial (~3000 words) that walks from beginner basics to
intermediate concepts. It’s structured so you can read it sequentially or jump to sections.
Complete Python Tutorial (Beginner to
Intermediate)
1. Introduction to Python
Python is a high-level, interpreted programming language known for its readability and
simplicity. It’s widely used in:
• Web development
• Data science & machine learning
• Automation & scripting
• Game development
• Cybersecurity
Why Python?
• Easy to learn (clean syntax)
• Large community
• Tons of libraries (e.g., NumPy, pandas, TensorFlow)
• Cross-platform
2. Installing Python
To get started:
1. Go to [Link]
2. Download Python (latest version recommended)
3. Install and check:
python --version
You can also use IDEs like:
• VS Code
• PyCharm
• Jupyter Notebook
3. Your First Python Program
print("Hello, World!")
Explanation:
• print() is a function used to display output.
4. Variables and Data Types
Variables
name = "Alice"
age = 25
height = 5.6
is_student = True
Data Types
Type Example
int 10
float 3.14
str "hello"
bool True / False
Dynamic Typing
Python automatically detects type:
x = 10
x = "Now I'm a string"
5. Input and Output
Input
name = input("Enter your name: ")
print("Hello", name)
Type Conversion
age = int(input("Enter age: "))
6. Operators
Arithmetic
+ - * / // % **
Example:
print(10 + 5) # 15
print(10 ** 2) # 100
Comparison
== != > < >= <=
Logical
and or not
7. Conditional Statements
age = 18
if age >= 18:
print("Adult")
elif age > 13:
print("Teen")
else:
print("Child")
8. Loops
For Loop
for i in range(5):
print(i)
While Loop
count = 0
while count < 5:
print(count)
count += 1
Loop Control
break
continue
pass
9. Functions
Functions help organize code.
def greet(name):
return "Hello " + name
print(greet("Alice"))
Default Parameters
def greet(name="Guest"):
print("Hello", name)
Lambda Functions
square = lambda x: x * x
print(square(5))
10. Lists
Lists are ordered collections.
fruits = ["apple", "banana", "cherry"]
Access
print(fruits[0])
Modify
[Link]("orange")
[Link]("banana")
Loop
for fruit in fruits:
print(fruit)
11. Tuples
Immutable lists:
coordinates = (10, 20)
12. Dictionaries
Key-value pairs:
person = {
"name": "Alice",
"age": 25
}
print(person["name"])
Add / Update
person["city"] = "Toronto"
13. Sets
Unordered unique items:
numbers = {1, 2, 3, 3}
print(numbers) # {1, 2, 3}
14. String Manipulation
text = "Python"
print([Link]())
print([Link]())
print(len(text))
print(text[0:3])
15. File Handling
Writing to File
with open("[Link]", "w") as f:
[Link]("Hello World")
Reading
with open("[Link]", "r") as f:
print([Link]())
16. Exception Handling
try:
x = int(input("Enter number: "))
except ValueError:
print("Invalid input")
finally:
print("Done")
17. Object-Oriented Programming (OOP)
Class Example
class Person:
def __init__(self, name):
[Link] = name
def greet(self):
print("Hello", [Link])
p = Person("Alice")
[Link]()
Inheritance
class Student(Person):
def study(self):
print([Link], "is studying")
18. Modules and Packages
Importing Modules
import math
print([Link](16))
Custom Module
Create [Link]:
def say_hello():
print("Hello!")
Use it:
import mymodule
mymodule.say_hello()
19. Working with Libraries
Example: Random
import random
print([Link](1, 10))
20. List Comprehensions
squares = [x*x for x in range(5)]
print(squares)
21. Working with Dates
from datetime import datetime
now = [Link]()
print(now)
22. Virtual Environments
python -m venv env
source env/bin/activate # Mac/Linux
env\Scripts\activate # Windows
23. Basic Project: Number Guessing Game
import random
number = [Link](1, 100)
while True:
guess = int(input("Guess: "))
if guess < number:
print("Too low")
elif guess > number:
print("Too high")
else:
print("Correct!")
break
24. Introduction to Data Science
Popular libraries:
• NumPy → numerical computing
• pandas → data analysis
• matplotlib → visualization
Example:
import pandas as pd
data = {"name": ["Alice", "Bob"], "age": [25, 30]}
df = [Link](data)
print(df)
25. Web Development with Python
Frameworks:
• Flask (lightweight)
• Django (full-stack)
Flask Example
from flask import Flask
app = Flask(__name__)
@[Link]("/")
def home():
return "Hello World"
[Link]()
26. Automation with Python
Example: rename files
import os
for file in [Link]():
if [Link](".txt"):
[Link](file, "new_" + file)
27. Debugging Tips
• Use print()
• Use IDE debugger
• Break code into small parts
28. Best Practices
• Use meaningful variable names
• Keep functions small
• Follow PEP 8 style guide
• Comment your code
29. Common Mistakes
• Indentation errors
• Forgetting type conversion
• Infinite loops
• Mutable default arguments
30. Next Steps
After learning basics, explore:
• Data Science / AI
• Web Development
• Game Development
• APIs and backend systems
Final Thoughts
Python is one of the most versatile and beginner-friendly programming languages available
today. By mastering the basics—variables, loops, functions, and data structures—you unlock
the ability to build real-world applications.
The key to learning Python is consistent practice:
• Build small projects
• Read others’ code
• Experiment
If you want, I can:
• Turn this into a PDF or formatted notes
• Give you practice exercises
• Create a project roadmap (beginner → advanced)