Python Tutorial for Beginners
(Fun & Easy Steps to Learn Python!) 🐍✨
Python is a simple yet powerful programming language used for games, websites, data science, and more! Let’s learn the basics.
1. Installing Python
Download Python from python.org.
Run the installer and check "Add Python to PATH".
Open IDLE (Python’s built-in editor) or use VS Code.
2. Your First Python Program
Let’s write a simple program!
print("Hello, World!")
Run it:
Save as
hello.pyPress
F5in IDLE or run in terminal:python hello.py
Output:
Hello, World!
3. Variables & Data Types
Variables store data. Python has:
| Type | Example |
|---|---|
int | 5, -10 |
float | 3.14, -0.5 |
str | "Hello", 'a' |
bool | True, False |
name = "Alice" age = 10 height = 4.5 is_student = True print(name, "is", age, "years old.")
4. User Input
Ask for input with input():
name = input("What’s your name? ") print("Hi,", name + "!")
Output:
What’s your name? Bob Hi, Bob!
5. Math Operations
| Operator | Example | Result |
|---|---|---|
+ | 5 + 2 | 7 |
- | 5 - 2 | 3 |
* | 5 * 2 | 10 |
/ | 5 / 2 | 2.5 |
** | 5 ** 2 | 25 (5 squared) |
x = 10 y = 3 print(x + y) # Output: 13
6. Conditional Statements (if, else)
Make decisions in code!
age = int(input("How old are you? ")) if age >= 18: print("You’re an adult!") elif age >= 13: print("You’re a teenager!") else: print("You’re a kid!")
7. Loops
for Loop
Repeat code a set number of times.
for i in range(5): print("Hello!", i)
Output:
Hello! 0 Hello! 1 Hello! 2 Hello! 3 Hello! 4
while Loop
Repeat until a condition is False.
count = 0 while count < 3: print("Counting:", count) count += 1
Output:
Counting: 0 Counting: 1 Counting: 2
8. Lists (Like a Toy Box!)
Store multiple items in one variable.
toys = ["car", "doll", "ball"] print(toys[0]) # Output: car toys.append("robot") # Add new toy print(toys) # Output: ['car', 'doll', 'ball', 'robot']
9. Functions (Reusable Code Blocks)
def greet(name): print("Hello,", name) greet("Alice") # Output: Hello, Alice
10. Mini-Project: Guess the Number!
import random secret_num = random.randint(1, 10) guess = 0 while guess != secret_num: guess = int(input("Guess a number (1-10): ")) if guess < secret_num: print("Too low!") elif guess > secret_num: print("Too high!") print("You got it! The number was", secret_num)
What’s Next?
🚀 Try These:
Make a simple calculator (
+,-,*,/).Create a story generator (using
random).Learn Turtle Graphics (draw shapes with code!).