Complete Python Tutorial for Beginners (2025)
Welcome to the easiest way to learn Python! Whether you're completely new or brushing up your skills, this guide will walk you through the essentials — clearly and practically — with working code examples you can copy and try yourself.
1. Introduction to Python
Python is a powerful, easy-to-read programming language used in web development, automation, data science, AI, and more. It's known for its clean syntax and large community.
2. Your First Python Program
Let’s start by printing something to the screen:
print("Hello, Python!")
3. Variables and Data Types
Python is dynamically typed — you don’t need to declare the type.
name = "Alice"
age = 25
height = 5.4
is_student = True
4. User Input
Get input from the user using input().
name = input("Enter your name: ")
print("Welcome, " + name)
5. Conditional Statements
Use if, elif, and else to make decisions.
age = int(input("Enter your age: "))
if age >= 18:
print("You're an adult.")
elif age > 12:
print("You're a teenager.")
else:
print("You're a child.")
6. Loops (for and while)
For Loop
for i in range(5):
print("Iteration", i)
While Loop
count = 0
while count < 5:
print(count)
count += 1
7. Functions
Functions allow you to reuse code and make programs modular.
def greet(name):
print("Hello,", name)
greet("Alice")
8. Lists
Lists hold multiple items and are very flexible.
fruits = ["apple", "banana", "cherry"]
print(fruits[1]) # Outputs 'banana'
fruits.append("orange")
9. Dictionaries
Dictionaries store data as key-value pairs.
person = {
"name": "Bob",
"age": 30
}
print(person["name"])
10. Classes and Objects
Python is object-oriented. You can create your own types using classes.
class Person:
def __init__(self, name):
self.name = name
def greet(self):
print("Hi, I'm", self.name)
p = Person("Alice")
p.greet()
11. Exception Handling
Handle errors gracefully using try-except blocks.
try:
num = int(input("Enter a number: "))
print(10 / num)
except ZeroDivisionError:
print("You can't divide by zero!")
except ValueError:
print("Invalid input.")
12. File Handling
You can read/write files easily.
# Write to a file
with open("demo.txt", "w") as file:
file.write("Hello, File!")
# Read from a file
with open("demo.txt", "r") as file:
print(file.read())
13. Useful Built-in Functions
len()– Length of an objecttype()– Get type of variablerange()– Generate a sequence of numberssum()– Sum of a listmax(),min()– Get maximum and minimum
14. Libraries to Explore
- math – For mathematical operations
- random – For generating random numbers
- datetime – For working with dates and times
- os – Interact with the operating system
15. Final Tips
- Practice coding every day — it builds confidence.
- Use Python's REPL or online interpreters to try code quickly.
- Break down problems into smaller steps.
- Explore small projects like a calculator, quiz app, or file organizer.
16. Python OOP (Object-Oriented Programming)
Python supports Object-Oriented Programming (OOP), which helps you organize code using classes and objects. Let’s go step-by-step through its core concepts:
1. Class and Object
A class is a blueprint, and an object is an instance of that blueprint.
class Car:
def __init__(self, brand, model):
self.brand = brand
self.model = model
def drive(self):
print(f"{self.brand} {self.model} is driving.")
# Creating an object
my_car = Car("Toyota", "Corolla")
my_car.drive()
2. Inheritance
Inheritance allows one class to use the properties and methods of another class.
class Animal:
def speak(self):
print("Animal speaks")
class Dog(Animal):
def bark(self):
print("Dog barks")
d = Dog()
d.speak()
d.bark()
3. Encapsulation
Encapsulation is about hiding data. We use underscore `_` or double underscore `__` to indicate protected/private variables.
class Person:
def __init__(self, name, age):
self.__name = name # private variable
self.__age = age
def get_info(self):
return f"{self.__name} is {self.__age} years old"
p = Person("John", 30)
print(p.get_info())
4. Abstraction
Abstraction hides complex details and shows only essential features. You can use abstract classes using the `abc` module.
from abc import ABC, abstractmethod
class Shape(ABC):
@abstractmethod
def area(self):
pass
class Square(Shape):
def __init__(self, side):
self.side = side
def area(self):
return self.side * self.side
s = Square(5)
print(s.area())
5. Polymorphism
Polymorphism means same method name, different behaviors.
class Bird:
def sound(self):
print("Bird makes sound")
class Sparrow(Bird):
def sound(self):
print("Sparrow chirps")
class Owl(Bird):
def sound(self):
print("Owl hoots")
for bird in [Sparrow(), Owl()]:
bird.sound()
Summary: OOP makes your code reusable, modular, and easier to maintain. Start applying these concepts to your small projects and watch your Python skills grow!
