Python Fundamentals · Units 1–2

Introduction & Setup

What Python is and your first program

First program

Make Python speak

Change the message, then run it. Python executes here in your browser.

Hello, World!
Starting up Python…
print("Hello, World!")
The editor is ready while Python loads in the background.

Output

Your program's output will appear here.
Common Python mistakes

NameError: name 'mark' is not defined

NameError: A name was used before Python could find a variable or function with that name.

IndexError: list index out of range

IndexError: The requested position is outside the items in this list or sequence.

KeyError: 'email'

KeyError: That key does not exist in this dictionary.

TypeError: can only concatenate str (not "int") to str

TypeError: This operation does not work with the kind of value it received.

ZeroDivisionError: division by zero

ZeroDivisionError: A number cannot be divided by zero.

SyntaxError: invalid syntax

SyntaxError: Python could not understand the structure of this line. Check spelling, brackets, colons, and quotes.

IndentationError: expected an indented block

IndentationError: The spaces at the start of a line do not match Python's block structure.

A language made to be readable

Python is a high-level, interpreted programming language. Its interpreter reads and runs your instructions, so you can test a small change without a separate compile step.

Open source

Anyone can use it, study how it works, and contribute.

Interpreted

The Python interpreter runs your instructions as a program.

Readable

Indentation and plain words make code easier to follow.

Useful libraries

Ready-made tools support science, web apps, and automation.

Created by Guido van Rossum, Python was first released in 1991. Today it is used for scripting, data analysis, education, and many other kinds of software.

Program structure

Read code one instruction at a time

A Python program is a sequence of statements. A statement can call a function such as print(). A colon introduces a block, and indentation shows which statements belong inside it.

student = "Mira"
if student == "Mira":
    print("Welcome, Mira!")

The indented line belongs to the if statement. Keep indentation consistent.

Keyword or identifier?

Keywords have a reserved meaning in Python. An identifier is a name you choose for a variable, function, or class.

“student_name” can be used as an identifier.

Explore Python keywords
FalseNoneTrueandasassertasyncawaitbreakclasscontinuedefdelelifelseexceptfinallyforfromglobalifimportinislambdanonlocalnotorpassraisereturntrywhilewithyieldmatchcase