← Back to Tutorials

Python for Beginners: Complete Tutorial

Learn Python programming from scratch with practical examples and hands-on coding exercises. Perfect for absolute beginners.

Why Learn Python?

Python is one of the most popular and beginner-friendly programming languages in the world. It's used by companies like Google, Netflix, NASA, and Instagram for everything from web development to artificial intelligence.

<div><span>Easy to learn with simple syntax</span></div><div><span>Huge community and resources</span></div><div><span>Versatile - web, data science, AI, automation</span></div><div><span>High-paying job opportunities</span></div>
1. Your First Python Program

Let's start with the classic "Hello, World!" program. This is traditionally the first program every programmer writes:

print("Hello, World!")

That's it! Just one line. The print() function displays text on the screen. Notice how simple and readable Python is.

2. Variables and Data Types

What are Variables?

Variables are containers for storing data. In Python, you don't need to declare the type - Python figures it out automatically!

# Strings (text)
name = "Alice"
message = "Hello, Python!" # Numbers
age = 25
price = 19.99 # Booleans (True/False)
is_student = True
is_logged_in = False # Print them out
print(name) # Output: Alice
print(age) # Output: 25

Common Data Types

<div><div><div>String</div> <div>Text enclosed in quotes</div></div> <code>"Hello"</code></div><div><div><div>Integer</div> <div>Whole numbers</div></div> <code>42</code></div><div><div><div>Float</div> <div>Decimal numbers</div></div> <code>3.14</code></div><div><div><div>Boolean</div> <div>True or False values</div></div> <code>True/False</code></div><div><div><div>List</div> <div>Ordered collection of items</div></div> <code>[1, 2, 3]</code></div>
3. Basic Operations

Math Operations

# Addition
result = 10 + 5 # 15 # Subtraction
result = 10 - 5 # 5 # Multiplication
result = 10 * 5 # 50 # Division
result = 10 / 5 # 2.0 # Power
result = 2 ** 3 # 8 (2 to the power of 3)

String Operations

# Combining strings
first_name = "John"
last_name = "Doe"
full_name = first_name + " " + last_name # "John Doe" # String repetition
laugh = "ha" * 3 # "hahaha" # String length
message = "Hello"
length = len(message) # 5
4. Conditional Statements (if/else)

Conditional statements let your program make decisions based on conditions:

age = 18 if age >= 18: print("You are an adult")
else: print("You are a minor") # Multiple conditions
score = 85 if score >= 90: print("Grade: A")
elif score >= 80: print("Grade: B")
elif score >= 70: print("Grade: C")
else: print("Grade: F")

Important:

Python uses indentation (spaces or tabs) to define code blocks. Make sure to indent consistently!

5. Loops - Repeating Actions

For Loops

Use for loops to repeat an action a specific number of times:

# Print numbers 1 to 5
for i in range(1, 6): print(i) # Loop through a list
fruits = ["apple", "banana", "cherry"]
for fruit in fruits: print(fruit)

While Loops

While loops continue until a condition becomes False:

count = 0
while count < 5: print(count) count += 1 # Increment by 1
6. Functions - Reusable Code

Functions let you organize code into reusable blocks:

# Define a function
def greet(name): return f"Hello, {name}!" # Call the function
message = greet("Alice")
print(message) # Output: Hello, Alice! # Function with multiple parameters
def calculate_area(width, height): area = width * height return area result = calculate_area(5, 10)
print(result) # Output: 50
7. Lists - Storing Multiple Items

Lists are ordered collections that can hold multiple items:

# Create a list
numbers = [1, 2, 3, 4, 5]
fruits = ["apple", "banana", "cherry"] # Access items (indexing starts at 0)
first_fruit = fruits[0] # "apple" # Add items
fruits.append("orange") # Remove items
fruits.remove("banana") # List length
count = len(fruits) # Loop through list
for fruit in fruits: print(fruit)
Next Steps in Your Python Journey

Congratulations! You've learned the fundamentals of Python. Here's what to learn next:

<div><span>Dictionaries and sets for advanced data storage</span></div><div><span>File handling to read and write files</span></div><div><span>Error handling with try/except blocks</span></div><div><span>Object-oriented programming with classes</span></div><div><span>Working with libraries like NumPy and Pandas</span></div><div><span>Building web applications with Django or Flask</span></div>

Practice Python Online

Ready to write your own Python code? Use our online Python editor to practice these concepts, run code instantly, and see results in real-time - no installation required!