Python Tutorials β Learn Python Basics
π Getting Started with Python
Python is a highβlevel, interpreted programming language known for its readability. It's used in web development, data science, automation, and more.
To start, you can use the PyDebug Playground (no installation needed) or install Python from python playground.
πΉ Your First Program
print("Hello, World!")
This tells Python to output the text. print() is a builtβin function.
πΉ Variables and Data Types
name = "Alice" # string
age = 25 # integer
height = 5.7 # float
is_student = True # boolean
Common data types: str, int, float, bool, list, tuple, dict, set.
πΉ Basic Operations
sum = 10 + 5 # 15
product = 4 * 2 # 8
power = 2 ** 3 # 8
greeting = "Hello, " + name
is_adult = age >= 18 # True
πΉ Control Flow: ifβelifβelse
score = 85
if score >= 90:
print("A")
elif score >= 80:
print("B")
else:
print("C")
πΉ Loops: for and while
fruits = ["apple", "banana", "cherry"]
for fruit in fruits:
print(fruit)
count = 0
while count < 5:
print(count)
count += 1
πΉ Functions
def greet(name):
return f"Hello, {name}!"
print(greet("Bob"))
πΉ Lists and Dictionaries
numbers = [1, 2, 3]
numbers.append(4)
student = {"name": "Alice", "age": 25}
print(student["name"])
π§ The Learning Path That Actually Sticks
Most people learn Python in the wrong order. They watch long video courses, copy code that works on the instructor's machine, and feel productive β until they open a blank file and nothing comes out. Reading code is passive; writing code from memory is active, and only the second one survives a test, an interview, or a real project.
A path that reliably works has four stages, and you should rotate through them rather than "finishing" one before touching the next:
- Syntax in small doses. Learn a construct (say,
forloops) and use it within ten minutes in the Playground. Change one thing at a time and watch what breaks. - Read errors on purpose. Beginners flee from red text; experienced developers walk toward it. Deliberately write code that triggers each common error and read the full message β see the Python errors guide for the catalog.
- Fix other people's bugs. Debugging someone else's broken snippet trains pattern recognition faster than writing new code, because every bug is a lesson about a specific language rule. This is exactly what PyDebug's bug-fixing problems are built for.
- Predict before you run. Whenever you write a loop or a condition, pause and say out loud what it will print, then run it. Right prediction means you understand; wrong prediction is the most valuable learning moment you will find.
π§± The Data Structures Worth Real Practice
Python gives you four everyday containers. Knowing when each one is correct is what separates a beginner from a competent developer β the syntax itself takes minutes to learn.
lst = [3, 1, 2] # ordered, mutable β a to-do list you reorder
tpl = (33.9, -118.2) # ordered, fixed β a coordinate pair, a DB row
d = {"a": 1, "b": 2} # keyβvalue β a phone book, fast lookups
s = {3, 1, 2} # unique, unordered β "which ids have I seen?"
Three rules of thumb that prevent most beginner bugs:
- Use a set to remove duplicates and to test membership.
x in my_listscans every item;x in my_setis near-instant. For big data this is a real performance difference, not a micro-optimisation. - Never mutate a list while looping over it. Build a new list (or a comprehension) instead β half of all list bugs on PyDebug trace back to this one habit.
- Dictionary keys must be immutable. You can use strings, numbers, and tuples as keys; you cannot use lists. If you "need" a list as a key, you usually want a tuple.
β οΈ Beginner Mistakes That Look Harmless but Aren't
Calling string and list methods that don't mutate
name = "alice"
name.upper() # result thrown away!
print(name) # still "alice"
name = name.upper() # correct: strings are immutable
Confusing = assignment with == comparison
if age = 18: # SyntaxError in Python β assignment isn't an expression here
if age == 18: # comparison β this is what you meant
Assuming input() gives you a number
n = input("Count to: ") # always a string
for i in range(n): # TypeError: 'str' object cannot be interpreted
for i in range(int(n)): # convert first
Forgetting that range(1, 5) stops at 4
Slicing and range() both exclude the end value. It bites everyone β see the glossary entry for slices, then drill it until it's automatic.
π A Realistic Two-Week Plan
Ten focused minutes a day beats a weekend cram, and this plan is built on that rule. Every day has one short learn step and one practice step.
- Days 1β2 β variables & types. Learn
str/int/float/bool; practice: the easy strings and functions problems filtered by difficulty. - Days 3β4 β conditionals & truthiness. Learn
if/elif/elseand which values are "falsy"; practice: comparison problems. - Days 5β6 β loops. Learn
for,while,range,break/continue; practice: every loops problem you can finish. - Days 7β8 β lists & dictionaries. Learn indexing, slicing,
.get(); practice: lists and dictionaries problems. - Days 9β10 β functions. Learn parameters, return values, scope; practice: functions problems, including the mutable-default trap.
- Days 11β12 β reading errors & debugging method. Read the errors guide and the debugging guide; practice: solve three problems without running the code first β predict, then check.
- Days 13β14 β output prediction & review. Do a session of prediction practice, then re-solve two problems you failed in week one. The speed difference is your proof of progress.
Track the streak and XP on your dashboard as you go β the practice guide explains why daily spacing beats marathon sessions.
Practice these basics on our Problems page to strengthen your debugging skills β every problem runs entirely in your browser, no setup required.
π Keep Going
- PyDebug Blog β expert guides, articles, and bug-fixing strategies.
- 15 Common Python Errors Guide β root causes and exact fixes for top Python bugs.
- Python debugging β what to do the moment something breaks.
- Common Python errors β the messages you will actually meet.
- How to practise Python β turning tutorials into skill.
- Python glossary β every term used on this page, defined.