← Back to PyDebug

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:

  1. Syntax in small doses. Learn a construct (say, for loops) and use it within ten minutes in the Playground. Change one thing at a time and watch what breaks.
  2. 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.
  3. 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.
  4. 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_list scans every item; x in my_set is 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.

  1. Days 1–2 β€” variables & types. Learn str/int/float/bool; practice: the easy strings and functions problems filtered by difficulty.
  2. Days 3–4 β€” conditionals & truthiness. Learn if/elif/else and which values are "falsy"; practice: comparison problems.
  3. Days 5–6 β€” loops. Learn for, while, range, break/continue; practice: every loops problem you can finish.
  4. Days 7–8 β€” lists & dictionaries. Learn indexing, slicing, .get(); practice: lists and dictionaries problems.
  5. Days 9–10 β€” functions. Learn parameters, return values, scope; practice: functions problems, including the mutable-default trap.
  6. 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.
  7. 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.