If you’re just starting out with Python or want a solid reference that covers everything from installation to object-oriented programming, you’re in the right place. I’ve put together this guide to walk you through every major Python concept in the order you should actually learn it — no fluff, no skipping around.
Think of this page as your Python home base. Each section covers a concept at a surface level with working code examples, and I’ve linked the full deep-dive tutorials wherever you need to go further.
Let’s get into it.
What Is Python and Why Should You Learn It?
Python is a high-level, general-purpose programming language that’s become the go-to choice for everything from web development and automation to machine learning and data science. What makes it stand out is how readable it is — Python code often reads like plain English, which means the learning curve is much gentler compared to languages like Java or C++.
Here’s what makes Python worth your time:
- Simple syntax — you spend less time fighting the language and more time solving problems
- Massive ecosystem — libraries like NumPy, Pandas, Django, and TensorFlow cover almost every domain
- High demand — Python consistently tops the charts in developer surveys and job postings
- Versatile — use it for web apps, data pipelines, automation scripts, ML models, and even desktop GUIs
Whether you want to get into data science, build web applications, or just automate some repetitive tasks at work, Python is the right starting point.
Here are some tutorials, you must read.
| Tutorial | Description |
|---|---|
| Is Python a Good Language to Learn? | Career value, demand, and ecosystem in 2026 |
| What Is the Best Way to Learn Python? | Structured advice on the most effective path |
| Should I Learn Java or Python? | Practical comparison to help you decide |
| Should I Learn Python or C++? | Which language fits your goals better |
| JavaScript vs Python for Web Development | When to use each language for web apps |
| Python / vs // | Division vs floor division explained |
| Call by Value vs Call by Reference in Python | How Python really handles argument passing |
| For Loop vs While Loop in Python | When to use each loop type |
Setting Up Python on Your System
Before writing any code, you need Python installed on your machine. Here’s the quickest way to get set up on each OS.
First, you should learn how to set up Python on your system.
Let me explain to you how to download and install Python on Windows, Linux, and macOS.
Download and Install Python on Windows
Here are the steps to download and install Python on Windows OS. Here is also a video. that our team made it. You can follow along with.
Method 1: Using the Python Installer
- Download the Installer: Go to the official Python website and download the latest Python installer for Windows.
- Run the Installer: Open the downloaded file. Ensure you check the box that says “Add Python to PATH” before clicking “Install Now.”
- Verify Installation: Open Command Prompt and type
python --version. You should see the installed Python version.
Method 2: Using Chocolatey
- Install Chocolatey: Open PowerShell as an administrator and run:
Set-ExecutionPolicy AllSigned
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))- Install Python: Once Chocolatey is installed, run:
choco install python- Verify Installation: Open Command Prompt and type
python --version.
Download and Install Python on Linux
Method 1: Using Package Manager
- Update Package List: Open Terminal and run:
sudo apt update- Install Python:
sudo apt install python3- Verify Installation: Type
python3 --versionin Terminal.
Method 2: Building from Source
- Install Dependencies:
sudo apt install build-essential checkinstall
sudo apt install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev- Download Python Source: Go to the Python Downloads page and download the source code.
- Extract and Install:
tar -xvf Python-<version>.tgz
cd Python-<version>
./configure --enable-optimizations
make
sudo make install- Verify Installation: Type
python3 --version.
Download and Install Python on macOS
You can follow the steps below to download and install Python on macOS. You can also follow our step-by-step video.
Method 1: Using the Python Installer
- Download the Installer: Visit the official Python website and download the latest Python installer for macOS.
- Run the Installer: Open the downloaded file and follow the instructions.
- Verify Installation: Open Terminal and type
python3 --version.
Method 2: Using Homebrew
- Install Homebrew: Open Terminal and run:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"- Install Python:
brew install python- Verify Installation: Type
python3 --versionin Terminal.
Choosing an IDE for Python Development
Once Python is installed, you need somewhere to write your code. I’d recommend one of these:
- VS Code — lightweight, fast, excellent Python extension, free
- PyCharm — purpose-built for Python, great for larger projects
- Jupyter Notebook — perfect if you’re heading into data science
Your First Python Program
Let’s write the classic Hello World program in Python. Open your editor, create a file called hello.py, and type this:
print("Hello, World!")Run it from your terminal:
python hello.py
Output:
Hello, World!
That’s it. You just ran your first Python program. The print() function outputs text to the console — you’ll use it constantly while learning.
Comments in Python
Comments are lines Python ignores — they’re just for you (or whoever reads your code later):
# This is a single-line comment
"""
This is a multi-line comment.
Useful for longer explanations.
"""
Get into the habit of commenting your code from day one. Future you will be grateful.
Python Basics & Syntax Tutorials
| Tutorial | Description |
|---|---|
| Python Hello World Program in Visual Studio Code | Set up and run your first Python program in VS Code |
| Identifiers in Python: Rules, Examples, and Best Practices | Naming rules for variables, functions, and classes |
| Python If Not Statement | How and when to use the not keyword in conditions |
| Python Pass by Reference | How Python handles mutable vs immutable arguments |
| How to Handle Python Command Line Arguments | Use sys.argv and argparse for CLI programs |
| Understand _init_ Method in Python | What __init__ does and why every class needs it |
| What Does // Mean in Python? | Floor division explained with practical examples |
| Python / vs // | Regular division vs floor division side by side |
| Call By Value and Call By Reference in Python | How Python passes arguments — what actually changes |
| Difference Between args and kwargs in Python | When to use each and how they work together |
| How to Take Continuous Input in Python | Accept multiple inputs from a user in a loop |
| Switch Case in Python with User Input | Simulate switch-case using dicts and match |
| Python Stdin, Stdout, and Stderr | Understand standard input, output, and error streams |
| Exit Function in Python | Use sys.exit(), quit(), and exit() correctly |
| How to Make a .exe from a Python Script with PyInstaller | Package your Python script into a standalone executable |
Python Data Types
Every value in Python has a type. Understanding data types is the foundation of everything else, so spend time here before moving on.
Python’s core built-in types are:
| Type | Example | Description |
|---|---|---|
int | 42 | Whole numbers |
float | 3.14 | Decimal numbers |
str | "hello" | Text |
bool | True / False | True or False values |
list | [1, 2, 3] | Ordered, mutable collection |
tuple | (1, 2, 3) | Ordered, immutable collection |
dict | {"key": "value"} | Key-value pairs |
set | {1, 2, 3} | Unordered, unique elements |
name = "Alice" # str
age = 25 # int
height = 5.6 # float
is_student = True # bool
You don’t need to declare types explicitly — Python figures it out based on what you assign. This is called dynamic typing.
👉 Go deeper: Python Data Types – Complete Tutorial
Python Operators
Operators let you perform operations on values. Here are the main categories:
Arithmetic Operators
x = 10
y = 3
print(x + y) # 13 — Addition
print(x - y) # 7 — Subtraction
print(x * y) # 30 — Multiplication
print(x / y) # 3.33 — Division
print(x % y) # 1 — Modulus (remainder)
print(x ** y) # 1000 — Exponentiation
print(x // y) # 3 — Floor Division
Comparison Operators
These return True or False:
print(10 == 10) # True
print(10 != 5) # True
print(10 > 3) # True
print(10 < 3) # False
Logical Operators
print(True and False) # False
print(True or False) # True
print(not True) # False
One thing I find trips up beginners — = is assignment (store a value), == is comparison (check if two things are equal). Don’t mix them up.
👉 Go deeper: Python Operators – Complete Tutorial
Conditional Statements and Loops
This is where your programs start making decisions and repeating work automatically.
If / Elif / Else
age = 20
if age < 18:
print("You're a minor.")
elif age == 18:
print("You just turned 18!")
else:
print("You're an adult.")
Python uses indentation (4 spaces) to define code blocks — there are no curly braces like in JavaScript or Java. Getting the indentation right matters.
For Loops
Use a for loop when you know how many times you want to repeat something:
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
print(fruit)
Using range() to loop a specific number of times:
for i in range(5):
print(i) # Prints 0, 1, 2, 3, 4
While Loops
Use a while loop when you want to keep going until a condition changes:
count = 0
while count < 5:
print(count)
count += 1
Break and Continue
break— exit the loop immediatelycontinue— skip the current iteration and move to the next one
for i in range(10):
if i == 5:
break # Stops at 5
print(i)
for i in range(10):
if i == 5:
continue # Skips 5, keeps going
print(i)
👉 Go deeper: Conditional Statements & Loops – Complete Tutorial
Python Functions
Functions let you write code once and reuse it everywhere. If you find yourself copy-pasting the same block of code, that’s your signal to turn it into a function.
Defining and Calling a Function
def greet(name):
return f"Hello, {name}!"
print(greet("Alice")) # Hello, Alice!
print(greet("Bob")) # Hello, Bob!
Default Arguments
def greet(name="Guest"):
return f"Hello, {name}!"
print(greet()) # Hello, Guest!
print(greet("Alice")) # Hello, Alice!
*args and **kwargs
When you don’t know how many arguments will be passed:
def add(*args):
return sum(args)
print(add(1, 2, 3, 4)) # 10
def display_info(**kwargs):
for key, value in kwargs.items():
print(f"{key}: {value}")
display_info(name="Alice", age=25, city="New York")
Lambda Functions
Quick, one-line anonymous functions:
square = lambda x: x ** 2
print(square(5)) # 25
Lambdas are especially handy with map(), filter(), and sorted().
👉 Go deeper: Python Functions – Complete Tutorial
Python Data Structures
Python has four built-in data structures you’ll use constantly. Knowing when to use which one is a key skill.
Lists
Ordered, mutable — you can add, remove, and change items:
fruits = ["apple", "banana", "cherry"]
fruits.append("mango") # Add to end
fruits.insert(0, "grape") # Insert at position
fruits.remove("banana") # Remove by value
print(fruits[0]) # Access by index
print(fruits[1:3]) # Slicing
👉 Go deeper: Python Lists – Complete Tutorial
Tuples
Ordered but immutable — once created, you can’t change them. Use them for data that shouldn’t change:
coordinates = (40.7128, -74.0060)
print(coordinates[0]) # 40.7128
# coordinates[0] = 50 # This will raise a TypeError
👉 Go deeper: Python Tuples – Complete Tutorial
Dictionaries
Key-value pairs — think of them like a real dictionary where you look up a word (key) to get its definition (value):
person = {"name": "Alice", "age": 25, "city": "New York"}
print(person["name"]) # Alice
person["email"] = "a@b.com" # Add new key
del person["age"] # Remove a key
for key, value in person.items():
print(f"{key}: {value}")👉 Go deeper: Python Dictionaries – Complete Tutorial
Sets
Unordered collections of unique values — duplicates are automatically removed:
numbers = {1, 2, 3, 3, 4, 4, 5}
print(numbers) # {1, 2, 3, 4, 5}
numbers.add(6)
numbers.remove(1)
# Set operations
a = {1, 2, 3}
b = {3, 4, 5}
print(a | b) # Union: {1, 2, 3, 4, 5}
print(a & b) # Intersection: {3}
print(a - b) # Difference: {1, 2}👉 Go deeper: Python Sets – Complete Tutorial
Arrays
Python arrays (from the array module) store elements of a single data type and are more memory-efficient than lists for large numeric data:
import array as arr
numbers = arr.array('i', [1, 2, 3, 4, 5])
numbers.append(6)
print(numbers[0]) # 1
For serious numerical work, you’ll quickly move to NumPy arrays — but it’s good to understand the built-in array module first.
👉 Go deeper: Python Arrays – Complete Tutorial
File Handling in Python
Reading and writing files is something almost every real-world Python program does. The with statement is the cleanest way to handle files — it automatically closes the file even if something goes wrong:
Reading a File
with open("example.txt", "r") as file:
content = file.read()
print(content)Writing to a File
with open("output.txt", "w") as file:
file.write("Hello, file!\n")
file.write("Second line.")Appending to a File
with open("output.txt", "a") as file:
file.write("\nAppending this line.")Reading Line by Line
with open("example.txt", "r") as file:
for line in file:
print(line.strip())Common file modes:
"r"— read"w"— write (overwrites existing content)"a"— append"rb"/"wb"— binary read/write (for images, PDFs, etc.)
👉 Go deeper: Python File Handling – Complete Tutorial
Exception Handling in Python
Things go wrong in programs — files don’t exist, users enter the wrong input, network requests fail. Exception handling lets your program deal with these situations gracefully instead of crashing.
Basic Try / Except
try:
result = 10 / 0
except ZeroDivisionError:
print("You can't divide by zero!")
Catching Multiple Exceptions
try:
number = int(input("Enter a number: "))
result = 100 / number
except ValueError:
print("That's not a valid number.")
except ZeroDivisionError:
print("Can't divide by zero.")
The Finally Block
finally always runs — whether an exception happened or not. Useful for cleanup:
try:
file = open("data.txt", "r")
content = file.read()
except FileNotFoundError:
print("File doesn't exist.")
finally:
print("This always runs.")
Raising Your Own Exceptions
def set_age(age):
if age < 0:
raise ValueError("Age can't be negative.")
return age
try:
set_age(-5)
except ValueError as e:
print(e) # Age can't be negative.
👉 Go deeper: Python Exception Handling – Complete Tutorial
Object-Oriented Programming (OOP) in Python
OOP is how you organize larger Python programs. Instead of writing a long list of functions, you group related data and behavior together into classes.
Defining a Class
class Dog:
def __init__(self, name, breed):
self.name = name
self.breed = breed
def bark(self):
return f"{self.name} says: Woof!"
my_dog = Dog("Rex", "Labrador")
print(my_dog.bark()) # Rex says: Woof!
__init__is the constructor — it runs automatically when you create a new objectselfrefers to the current instance of the class
Inheritance
Inheritance lets one class reuse the code of another:
class Animal:
def __init__(self, name):
self.name = name
def speak(self):
return "Some sound"
class Dog(Animal):
def speak(self):
return f"{self.name} says Woof!"
class Cat(Animal):
def speak(self):
return f"{self.name} says Meow!"
dog = Dog("Rex")
cat = Cat("Whiskers")
print(dog.speak()) # Rex says Woof!
print(cat.speak()) # Whiskers says Meow!
Encapsulation
Encapsulation is about keeping internal details private. In Python, you prefix attributes with __ to make them private:
class BankAccount:
def __init__(self, balance):
self.__balance = balance # private
def get_balance(self):
return self.__balance
def deposit(self, amount):
if amount > 0:
self.__balance += amount
Four Pillars of OOP at a Glance
| Concept | What It Means |
|---|---|
| Encapsulation | Bundle data and methods together; hide internal details |
| Inheritance | A child class inherits properties from a parent class |
| Polymorphism | Different classes can be used through the same interface |
| Abstraction | Hide complexity, expose only what’s needed |
👉 Go deeper: Object-Oriented Programming in Python – Complete Tutorial
Modules and Packages
You don’t have to write everything from scratch. Python’s standard library and third-party packages give you ready-made tools for almost any task.
Importing Built-in Modules
import math
print(math.sqrt(25)) # 5.0
print(math.pi) # 3.14159...
import random
print(random.randint(1, 10)) # Random number between 1 and 10
import datetime
today = datetime.date.today()
print(today)
Installing Third-Party Packages
Use pip to install packages from PyPI:
pip install requests
pip install numpy
pip install pandas
Creating Your Own Module
Any .py file is a module. Create utils.py:
# utils.py
def add(a, b):
return a + b
def multiply(a, b):
return a * b
Then import it in your main script:
# main.py
from utils import add, multiply
print(add(3, 4)) # 7
print(multiply(3, 4)) # 12
What’s Next? Explore Python Libraries
Once you’re comfortable with the fundamentals above, the next step is diving into Python’s library ecosystem. Here’s where most Python careers actually take off:
Data Science & Machine Learning
| Library | What It’s For |
|---|---|
| NumPy | Arrays, matrix operations, numerical computing |
| Pandas | Data manipulation, cleaning, analysis |
| Matplotlib | Data visualization and charts |
| Scikit-learn | Machine learning models and pipelines |
| SciPy | Scientific and statistical computing |
| TensorFlow | Deep learning and neural networks |
| Keras | High-level deep learning API |
| PyTorch | Research-grade deep learning |
Web Development
| Library | What It’s For |
|---|---|
| Django | Full-stack web framework, REST APIs, ORM |
GUI & Desktop Apps
| Library | What It’s For |
|---|---|
| Tkinter | Built-in Python GUI toolkit |
| PyQt6 | Professional desktop application development |
| Turtle | Graphics and animations, great for beginners |
Free Python & Machine Learning Training Course
If you learn better by watching and coding along, check out our completely free Python and Machine Learning Training Course. It covers everything in this guide and goes much further — with 40 modules, 70+ hours of video, and 275+ downloadable source files. No sign-up required.
Quick Reference: Python Learning Path
Here’s the order I’d recommend working through everything:
- ✅ Install Python & set up your IDE
- ✅ Data Types — understand what kinds of values Python works with
- ✅ Operators — arithmetic, comparison, logical
- ✅ Conditionals & Loops — make decisions and repeat tasks
- ✅ Functions — write reusable, organized code
- ✅ Lists, Tuples, Dictionaries, Sets, Arrays — master data structures
- ✅ File Handling — read and write files
- ✅ Exception Handling — handle errors gracefully
- ✅ Object-Oriented Programming — write professional, scalable code
- 🚀 Pick a library path — Data Science, Web Dev, or GUI development