Open the app
  1. Home
  2. Lessons
  3. KS3 Computing
  4. First steps in Python

First steps in Python

🎬 The doodle video for this lesson is coming soon. Subscribe on YouTube to see it first.

Python is a textual programming language used by beginners and by professionals. You type the instructions, and spelling and punctuation matter.

Output with print

print shows something on the screen.
print("Hello, world!")
Text in quotes is a string. Numbers do not need quotes: print(5 + 2) shows 7.

Variables

A variable is a named box that stores a value. = puts a value into it.
name = "Sam"
age = 12
print("Hello", name)
print(age + 1)
Output:
Hello Sam
13
Variable names cannot contain spaces or start with a number. Use names that explain the data, such as score.

Input and data types

input reads what the user types. It always gives a string.
name = input("Your name? ")
To do maths with typed numbers, convert with int() for whole numbers:
age = int(input("Age? "))
Watch out: "3" + "4" joins strings to make 34, but 3 + 4 is 7.
Worked example

What does this program print?
x = 5
x = x * 2
x = x - 3
print(x)

  1. x starts as 5.
  2. x = 5 * 2 = 10.
  3. x = 10 - 3 = 7.

Answer: 7

Key idea

print shows output, = stores a value in a variable, input reads text from the user and int() turns it into a whole number. Strings in quotes join together; numbers add.

Check you have got it

Answer 6 quick questions with instant marking. If you get one wrong, GCSE-ready shows you why and gives you another go. It is free, and you do not need an account.