Hey there! 👋 Ready to learn one of the coolest programming languages in the world?
Python is like giving instructions to a very smart friend — the computer! You just type what you want, and it does it. No complicated rules, just plain English-like commands. Let's start! 🚀
Imagine you have a super-smart assistant who can do math homework, create games, build websites, and even help robots move! That's what Python can do. Here's why it's awesome:
Python looks almost like English! No confusing symbols like { } or ; everywhere.
You can make your own games, quizzes, and even chatbots with Python!
NASA, Google, and even self-driving cars use Python. How cool is that?
Python can solve tough math problems in seconds — like a super calculator!
Websites, apps, science, art — Python is everywhere in the real world!
Most teachers and coders recommend Python as your very first language!
In Python, print() is how you tell the computer to show something on the screen. Think of it like writing a message on a whiteboard! ✍️
print("Hello!") tells the computer to say "Hello!" on the screen.print("Hello, World!") — The words inside quotes are what you want to show.Hello, World! below. You just wrote your first program! 🎉print() must be inside quotation marks " " — they tell Python "this is text, not a command!"A variable is like a box with a label. You put something inside the box and give it a name, so you can use it later!
age)= (this means "store")13)my_name or myName instead of my name. Also, they can't start with a number.age = 13 is correct, but 13 = age is WRONG! The value always goes on the right side.Just like you have different types of things in your school bag (books, pens, lunch box), Python has different types of data. Let's learn all of them!
Text — like your name. Always in "quotes"
x = "Hello"
Whole numbers — like age 13
x = 42
Decimal numbers — like marks 89.5
x = 3.14
True or False — like a switch
x = True
What if you want to store many values together? Like a list of all students in your class, or all your marks? Python gives you 4 powerful containers:
Ordered, changeable, allows duplicates
[1, 2, 3]
Ordered, unchangeable, allows duplicates
(1, 2, 3)
Unordered, no duplicates
{1, 2, 3}
Key-Value pairs, like a real dictionary!
{"a": 1}
| Feature | 📋 List [ ] |
📦 Tuple ( ) |
🎯 Set { } |
📖 Dict {k:v} |
|---|---|---|---|---|
| Ordered? | ✅ Yes | ✅ Yes | ❌ No | ✅ Yes (Python 3.7+) |
| Can change? | ✅ Yes | ❌ No | ✅ Yes | ✅ Yes |
| Duplicates? | ✅ Yes | ✅ Yes | ❌ No | ❌ No keys |
| Use when... | You need a shopping list | You need fixed data | You need unique items | You need name → value |
| Real-life analogy | 🎒 School bag | 📜 Certificate | 🃏 Card collection | 📒 Phone book |
A list is like your school bag 🎒 — you can put things in, take things out, rearrange them, and even put the same thing twice! It keeps everything in order.
[ ] means "list"
fruits.append("mango") puts a new item at the endfruits.remove("apple") takes out an itemfruits[0] gets the first item (Python starts counting from 0!)fruits[1] = "kiwi" replaces the second itemlen(fruits) tells you how many items are in the list[0], the second is [1], the third is [2], and so on. This is different from how we normally count!
fruits.sort() to arrange them alphabetically. Or fruits.reverse() to flip the order!A tuple is like a sealed envelope 📜 — once you put something inside and seal it, you can't change it! But you can still read what's inside.
( ) means "tuple"
TypeError: 'tuple' object does not support item assignment. That's Python's way of saying "Nope! This is sealed!" 🔒
[ ] = List (changeable) vs ( ) = Tuple (unchangeable). The brackets tell you the difference!A set is like a trading card collection 🃏 — you only keep one of each. No duplicates allowed! And the order doesn't matter — you just care about which items you have.
{ } means "set"
[0] like lists"apple" in fruits is super quick with sets!set1 & set2 = common items (intersection), set1 | set2 = all items (union), set1 - set2 = items only in set1 (difference)
{} creates an empty dictionary, not a set! To create an empty set, use set(). Only {"a", "b"} with values inside creates a set.
A dictionary is like a phone book 📒 — you look up someone's name (the key) to find their phone number (the value). Every entry has a key : value pair!
{"key": "value"} means "dictionary"
"name": "Riya" — "name" is the key, "Riya" is the valuestudent["name"] gives you "Riya"student["age"] = 14 adds a new key or changes an existing onestudent["grade"] but "grade" doesn't exist, Python gives a KeyError! Always check if the key exists first, or use student.get("grade", "Not found") which won't crash.
Let's see all four collection types together so you can compare them! 👀
Life is full of decisions! "If it's raining, I'll take an umbrella. Else, I won't." Python makes decisions the same way using if, elif, and else.
if, elif, and else. Python NEEDS those spaces! No spaces = Error! ❌marks = 78 to marks = 95 or marks = 35 and run again to see different results!Imagine you have to write "I will be on time" 100 times. 😫 That's boring! Python loops can do it in one line! There are two types: for and while.
A function is like a recipe 🍳 — you write the steps once, then use it anytime! Instead of writing the same code over and over, you put it in a function and just call it!
Let's combine everything you've learned! Build a simple student report card using variables, lists, dictionaries, conditions, and loops!
Write any Python code you want! This is your sandbox to experiment freely. 🏖️
Test what you've learned! Choose the best answer for each question. 🧠
print("Hello") do?len([1,2,3])?Check off each topic as you complete it! Your progress is saved in your browser. 🏆
0 of 10 completed
You've completed the Python basics! Here are some exciting paths to continue your coding journey:
Learn Pygame and create your own computer games!
Learn Flask/Django to build real websites!
Train computers to think and learn!
Keep coding, keep learning! You're doing amazing! 🌟