Lesson 1 of 6 · Python

Your first Python program

A program is a set of instructions. In this lesson you will run your first Python statements, use print() to display information and learn how to read a simple error message.

What happens when Python runs?

Python follows your instructions from top to bottom. Each statement tells the interpreter to do one small job. A program can be only one line long, or it can contain thousands of lines arranged into functions and modules.

For now, keep the instructions simple. Write one statement, run it, check the output and then change something. That loop is more useful than copying a long block of code without understanding it.

Display output with print()

The print() function sends information to the output area. Put the value you want to display between its parentheses. Text must be written inside matching single or double quotation marks.

Each call to print() normally starts a new output line. You can pass more than one value by separating them with commas. Python inserts a space between those values by default.

Comments and common mistakes

A comment starts with #. Python ignores the text after it on that line, so comments are useful for explaining why a piece of code exists. Comments should clarify the code, not repeat every obvious instruction.

Python is case-sensitive: print and Print are different names. A missing quote or closing parenthesis causes a syntax error. When an error appears, read the final line first and check the line number it reports.

main.py
print("Hello, Code Campus!")
print("I am learning Python.")
print("One line at a time.")
messages.py
# This is a comment
name = "Aarav"
print("Welcome", name)
print("Your first program is running.")

Try it yourself

The code examples above are for reference. Copy the relevant example into the editor, press Run, then change it and run it again.

Code Campus
Your turn

Print your name, your course and one skill you want to learn. Use three separate print() statements, then add a comment above them.

Show a hint
print("My name is Alex")
print("I am studying computer science")
print("I want to learn Python")

#CodeCampus

Code Campus