Python Syntax

A quick, student-friendly guide to core Python concepts. Keep this page open while coding in the sandbox.

We focus on fundamentals first. Advanced topics can come later after these feel easy.

What Python Syntax Means

Syntax is the set of writing rules that helps Python understand your code. Small details like colons and indentation matter.

In [1]Code cellpyodide

Mini challenge: Write a 2-line program that prints your name and your favorite subject.

Printing Output

Use print() to show results, messages, and variable values.

In [2]Code cellpyodide

Mini challenge: Print three lines: your name, your grade level, and your favorite snack.

Variables and Basic Data Types

Variables store information your program can use and change.

In [3]Code cellpyodide

Mini challenge: Create 4 variables about yourself (name, age, hobby_count, likes_python).

User Input

input() lets users type answers while your program runs.

In [4]Code cellpyodide

Mini challenge: Ask for a user's favorite number and print number + 10.

Math and Operators

Operators help with calculations and comparisons.

In [5]Code cellpyodide

Mini challenge: Pick two numbers and print their sum, product, and whether the first is bigger.

Conditionals (if / elif / else)

Conditionals let your code make choices.

In [6]Code cellpyodide

Mini challenge: Make a program that prints different messages for scores: A, B, or needs practice.

Loops

Loops repeat code without copy-pasting lines.

In [7]Code cellpyodide

Mini challenge: Use a for loop to print numbers 1 through 10.

Functions

Functions let you reuse steps and keep code organized.

In [8]Code cellpyodide

Mini challenge: Write a function called double that returns a number times 2.

Lists

Lists store multiple values in order.

In [9]Code cellpyodide

Mini challenge: Create a list of 4 games, then print each game in a loop.

Strings

Strings are text values you can slice and change.

In [10]Code cellpyodide

Mini challenge: Store your favorite word and print its first letter and total length.

Dictionaries and Tuples

Dictionaries map keys to values, and tuples store fixed groups of values.

In [11]Code cellpyodide

Mini challenge: Make a dictionary with keys name and favorite_color, then print both values.

Classes (Beginner Intro)

Classes are blueprints for creating objects with data and actions.

In [12]Code cellpyodide

Mini challenge: Create a class called Student with name and a method that prints a greeting.

Simple Debugging Habits

Debugging helps you fix errors and learn faster.

In [13]Code cellpyodide

Mini challenge: Break a tiny program on purpose, then fix it by reading the error message.

Not Covered Yet (On Purpose)

We are skipping advanced topics for now: inheritance, files, decorators, and deeper error handling. Mastering the basics first makes advanced Python much easier later.

Back to home