BrightPath
Back to Course
Year 9 Coding

Introduction to Python

Discover what Python is, how to run your first program, and learn the basics of printing output and writing comments.

What is Python?

Python is one of the world's most popular programming languages. It was created by Guido van Rossum in 1991 and is known for being easy to read and write. Python is used for web development, data science, artificial intelligence, game design, and much more.

Unlike some other languages, Python reads almost like English, which makes it a fantastic first programming language. Let's start with the most famous program in all of coding:

# This is your first Python program!
print("Hello, World!")

When you run this program, Python will display the text Hello, World! on the screen. The print() function tells Python to output whatever is inside the parentheses.

Running Python Code and Writing Comments

You can run Python code using an online editor (like Replit or Trinket), or by installing Python on your computer and running files from the terminal. Python files end with the .py extension.

Comments are notes you leave in your code for yourself or other programmers. Python ignores comments when running your program. You write a comment using the # symbol.

# This is a comment - Python will skip this line
print("This line will run")  # You can also comment at the end

# Comments help explain what your code does
# They make your code easier to understand

Good programmers write comments to explain why they wrote something, not just what the code does. This is especially helpful when you come back to your code weeks later.

The print() Function

The print() function is your main tool for displaying output. You can print text (strings), numbers, and even calculations.

# Printing text (strings)
print("My name is Alex")
print('You can use single quotes too')

# Printing numbers
print(42)
print(3.14)

# Printing calculations
print(10 + 5)      # Output: 15
print(100 - 37)    # Output: 63

# Printing multiple items
print("I am", 14, "years old")

Notice that when you print multiple items separated by commas, Python automatically adds spaces between them. The last line above would output: I am 14 years old.

Key Vocabulary

Python

A high-level, general-purpose programming language known for its clear, readable syntax.

print()

A built-in function that displays output to the screen. Whatever you put inside the parentheses gets printed.

Comment

A line starting with # that Python ignores. Used to explain code to humans.

String

Text data enclosed in quotation marks (either single '...' or double "...").

Worked Examples

1

Write a program that prints your name and age on separate lines.

# Printing personal info on separate lines
print("Name: Alex")
print("Age: 14")

Step 1: Use print() to display the name on the first line.

Step 2: Use a second print() to display the age on a new line.

Output: Name: Alex then Age: 14

2

Write a program that calculates and prints the result of 25 multiplied by 4.

# Calculate 25 times 4
print("25 x 4 =", 25 * 4)

Step 1: Use * for multiplication in Python.

Step 2: Print a label and the calculation together using a comma.

Output: 25 x 4 = 100

3

Add a comment explaining what this code does, then fix the error.

# Display a greeting message to the user
print("Welcome to BrightPath!")
# Note: The original had Print() with a capital P
# Python is case-sensitive, so it must be print()

Step 1: Python is case-sensitive, meaning Print and print are different.

Step 2: The correct function is lowercase: print().

Key point: Always use lowercase print() and remember that Python cares about capitalisation.

Knowledge Check

Select the correct answer for each question. Click "Check Answer" to see if you are right.

Question 1

What will the following code output?

print("Hello", "World")

Question 2

Which symbol is used to start a comment in Python?

Question 3

What will print(10 + 5) display?

Question 4

What is the file extension for Python programs?

Question 5

Which of the following is a valid Python string?

Key Concepts Summary

Year 8: Simulation Next: Python Variables