▶ TrainingGet Pro
All tools & lessonsAll toolsAllGet the appApp
Learning departments Music, Cookery, Programming and Art are open – explore →

Python for complete beginners

Glossary of code

Every word used in the Python course, explained in plain English with a tiny example. In the lessons, words with a dotted underline open this glossary as a pop-up.

A

algorithm

A set of step-by-step instructions for solving a problem or doing a task. A recipe is an algorithm; a program is an algorithm written in a programming language.

# make toast: an algorithm
print("1. Put bread in the toaster")
print("2. Wait")
print("3. Butter it")

Output

1. Put bread in the toaster
2. Wait
3. Butter it

See: Lesson 1: What is programming? · Lesson 4: Comments and how Python reads code coming soon

append

A list method that adds an item to the end of a list.

pets = ["cat"]
pets.append("dog")
print(pets)

Output

['cat', 'dog']

See: Lesson 17: Changing lists coming soon

argument

The value you put inside the brackets when you call a function. In print("Hi"), the argument is "Hi". A function can take several arguments, separated by commas.

print("Hi", "there")

Output

Hi there

See: Lesson 2: print() and strings · Lesson 20: Parameters and return coming soon

assignment

Storing a value in a variable using a single equals sign. x = 5 means "put 5 in the box called x", not "x equals 5" as in math.

score = 10
print(score)

Output

10

See: Lesson 5: Variables: boxes with labels coming soon

B

Boolean (bool)

A data type with only two possible values: True or False (with capital letters). Comparisons give Boolean answers.

print(5 > 3)
print(2 > 9)

Output

True
False

See: Lesson 10: True, False and comparisons coming soon

break

A keyword that stops a loop straight away, even if it would have carried on.

for n in range(10):
    if n == 3:
        break
    print(n)

Output

0
1
2

See: Lesson 15: Loop patterns coming soon

bug

A mistake in a program that stops it working, or makes it do the wrong thing.

print("Hello"  # bug: missing )

This example stops with a SyntaxError.

See: Lesson 3: Errors are normal

C

call (a function)

To tell a function to do its job, by writing its name followed by round brackets. print("Hi") calls the print function.

print("I am calling print")

Output

I am calling print

See: Lesson 2: print() and strings · Lesson 19: Your own functions coming soon

casting (converting types)

Changing a value from one data type to another, using int(), float() or str(). Also called type conversion.

age = "12"
print(int(age) + 1)

Output

13

See: Lesson 8: Data types and converting coming soon

code

The instructions of a program, written in a programming language. Writing them is called coding.

print("This line is code")

Output

This line is code

See: Lesson 1: What is programming?

comment

A note for humans, starting with #. Python ignores everything from the # to the end of the line.

# This is a comment
print("Comments are not run")

Output

Comments are not run

See: Lesson 4: Comments and how Python reads code coming soon

comparison operator

A symbol that compares two values and gives True or False: == (equal to), != (not equal to), <, >, <= and >=.

print(7 == 7)
print(7 != 7)

Output

True
False

See: Lesson 10: True, False and comparisons coming soon

concatenation

Joining strings end to end with +. No space is added, so put one in yourself if you need it.

print("sun" + "flower")

Output

sunflower

See: Lesson 2: print() and strings · Lesson 7: Working with text coming soon

condition

A question with a True or False answer, used by if and while to decide what to do.

temp = 30
if temp > 25:
    print("Hot!")

Output

Hot!

See: Lesson 11: Making decisions: if and else coming soon · Lesson 14: while loops coming soon

D

data type

The kind of value something is. The main ones: int (whole number), float (decimal), str (text) and bool (True/False). type() tells you a value's type.

print(type(3.5))

Output

<class 'float'>

See: Lesson 8: Data types and converting coming soon

debugging

Finding and fixing bugs. Read the error message, look at the line (and the one above), change one thing, run again.

print("Fixed!")  # after debugging

Output

Fixed!

See: Lesson 3: Errors are normal

def

The keyword that starts a function definition: def, the function's name, brackets and a colon. The indented lines below are the function's body.

def greet():
    print("Hello!")

greet()

Output

Hello!

See: Lesson 19: Your own functions coming soon

E

editor

The place where you type and change your code. The editor on these pages has line numbers, a Run button and an output box.

print("Typed in the editor")

Output

Typed in the editor

See: Lesson 1: What is programming?

elif

Short for "else if". Checks another condition when the ones above it were False. You can have as many elifs as you need.

mark = 65
if mark >= 80:
    print("Gold")
elif mark >= 60:
    print("Silver")

Output

Silver

See: Lesson 12: More choices: elif, and, or, not coming soon

else

The part of an if statement that runs when none of the conditions above it were True.

age = 9
if age >= 13:
    print("Teen")
else:
    print("Not a teen yet")

Output

Not a teen yet

See: Lesson 11: Making decisions: if and else coming soon

error message

What Python shows when it can't carry on. It tells you the line number, the type of error and some details.

pront("Hi")

This example stops with a NameError.

See: Lesson 3: Errors are normal

F

float

A number with a decimal point, such as 3.5 or 0.25. Dividing with / always gives a float.

print(7 / 2)

Output

3.5

See: Lesson 6: Numbers and math coming soon · Lesson 8: Data types and converting coming soon

for loop

A loop that repeats once for each item in a sequence, such as each number in a range or each item in a list.

for i in range(3):
    print("Hip hip hooray!")

Output

Hip hip hooray!
Hip hip hooray!
Hip hip hooray!

See: Lesson 13: Repeating with for and range() coming soon · Lesson 18: Looping through lists coming soon

f-string

A string with f before the opening quote mark. Anything inside { } is worked out and put into the text.

name = "Ada"
print(f"Hi {name}!")

Output

Hi Ada!

See: Lesson 7: Working with text coming soon

function

A named, ready-made job. print and input are built-in functions; you can also write your own with def. Run one by calling it with brackets.

print(len("hello"))

Output

5

See: Lesson 2: print() and strings · Lesson 19: Your own functions coming soon · Lesson 20: Parameters and return coming soon

I

if

A keyword that runs some code only when a condition is True. The line ends with a colon, and the code to run is indented underneath.

lives = 0
if lives == 0:
    print("Game over")

Output

Game over

See: Lesson 11: Making decisions: if and else coming soon

indentation

Spaces at the start of a line. Python uses indentation (usually 4 spaces) to show which lines belong inside an if, a loop or a function. Unexpected spaces cause an error.

if True:
    print("I am indented")

Output

I am indented

See: Lesson 3: Errors are normal · Lesson 11: Making decisions: if and else coming soon

index

The position of an item in a list or a character in a string. Counting starts at 0, so the first item is at index 0.

colors = ["red", "green", "blue"]
print(colors[0])

Output

red

See: Lesson 16: Lists and indexes coming soon

infinite loop

A loop that never stops, because its condition never becomes False. On these pages, a program that runs too long is stopped for you.

n = 1
while n > 0:
    n = n + 1  # never stops!

This program never ends, so it isn't shown running.

See: Lesson 14: while loops coming soon

input()

A function that waits for the user to type something and press Enter. It always gives back a string.

name = input("Your name? ")
print("Hi", name)

This example waits for the user to type.

See: Lesson 9: Asking questions with input() coming soon

instruction

One step that tells the computer to do something. A program is a list of instructions. In Python, each line is usually one instruction (also called a statement).

print("One instruction")

Output

One instruction

See: Lesson 1: What is programming?

integer (int)

A whole number with no decimal point, such as 7, 0 or -12.

print(3 + 4)

Output

7

See: Lesson 2: print() and strings · Lesson 6: Numbers and math coming soon · Lesson 8: Data types and converting coming soon

interpreter

The program that reads your Python code and carries it out, one line at a time from the top.

print("The interpreter runs this")

Output

The interpreter runs this

See: Lesson 1: What is programming?

iteration

Repeating a set of instructions – what loops do. One trip round a loop is also called an iteration.

for n in [1, 2, 3]:
    print(n * 10)

Output

10
20
30

See: Lesson 13: Repeating with for and range() coming soon

K

keyword

A word with a special meaning in Python, such as if, else, for, while, def and True. You can't use keywords as variable names.

if True:
    print("if and True are keywords")

Output

if and True are keywords

See: Lesson 5: Variables: boxes with labels coming soon · Lesson 11: Making decisions: if and else coming soon

L

len()

A function that gives the length of a string (number of characters) or of a list (number of items).

print(len("Python"))

Output

6

See: Lesson 7: Working with text coming soon · Lesson 16: Lists and indexes coming soon

list

A collection of items in order, inside square brackets and separated by commas. Lists can grow and change.

snacks = ["apple", "chips", "nuts"]
print(len(snacks))

Output

3

See: Lesson 16: Lists and indexes coming soon · Lesson 17: Changing lists coming soon · Lesson 18: Looping through lists coming soon

logical operators (and, or, not)

Words that combine conditions: and (both must be True), or (at least one True), not (flips True and False).

age = 12
print(age > 10 and age < 13)

Output

True

See: Lesson 12: More choices: elif, and, or, not coming soon

logic error

A bug where the program runs without any error message, but does the wrong thing. You find logic errors by checking the output.

print("3 spiders have", 3 + 8, "legs")  # should be 3 * 8

Output

3 spiders have 11 legs

See: Lesson 3: Errors are normal

loop

Code that repeats. Python has two kinds: for loops (repeat for each item) and while loops (repeat while a condition is True).

for i in range(2):
    print("Again!")

Output

Again!
Again!

See: Lesson 13: Repeating with for and range() coming soon · Lesson 14: while loops coming soon

M

method

A function that belongs to a value and is called with a dot, such as "hi".upper() or my_list.append(5).

print("shout".upper())

Output

SHOUT

See: Lesson 7: Working with text coming soon · Lesson 17: Changing lists coming soon

module

A file of extra ready-made code you can bring into your program with import – for example the random module, for random numbers.

import math
print(math.sqrt(81))

Output

9.0

See: Lesson 21: Modules: ready-made code coming soon

N

NameError

An error that means Python doesn't recognise a name: usually a spelling mistake, a capital letter, or text without quote marks.

print(hello)

This example stops with a NameError.

See: Lesson 3: Errors are normal

O

operator

A symbol that does something to values: + (add), - (subtract), * (multiply), / (divide), // (whole-number divide), % (remainder) and ** (power).

print(2 ** 3)

Output

8

See: Lesson 2: print() and strings · Lesson 6: Numbers and math coming soon

output

Anything a program shows to the user, such as text from print. In the editor, it appears in the output box.

print("This is output")

Output

This is output

See: Lesson 1: What is programming?

P

parameter

A name in a function's definition that receives a value when the function is called. In def greet(name):, name is a parameter.

def greet(name):
    print("Hello", name)

greet("Sam")

Output

Hello Sam

See: Lesson 20: Parameters and return coming soon

program

A list of instructions that tells a computer what to do. Apps, games and websites are all programs.

print("I am a tiny program")

Output

I am a tiny program

See: Lesson 1: What is programming?

programming (coding)

Writing instructions for a computer in a programming language such as Python.

print("I am programming!")

Output

I am programming!

See: Lesson 1: What is programming?

Python

A popular programming language that reads almost like English. It was created by Guido van Rossum and first released in 1991.

print("Python")

Output

Python

See: Lesson 1: What is programming?

R

random

A module for making random choices. random.randint(1, 6) gives a whole number from 1 to 6, like rolling a dice.

import random
roll = random.randint(1, 6)
print(1 <= roll <= 6)

Output

True

See: Lesson 21: Modules: ready-made code coming soon

range()

A function that makes a sequence of whole numbers. range(3) gives 0, 1, 2; range(1, 4) gives 1, 2, 3. It stops before the end number.

for n in range(1, 4):
    print(n)

Output

1
2
3

See: Lesson 13: Repeating with for and range() coming soon

return

A keyword that sends a value back from a function to the code that called it, and ends the function.

def double(n):
    return n * 2

print(double(21))

Output

42

See: Lesson 20: Parameters and return coming soon

run

To make the computer carry out a program's instructions. In the editor, press Run (or Ctrl + Enter).

print("Running!")

Output

Running!

See: Lesson 1: What is programming?

S

scope

Where in a program a variable can be used. A variable made inside a function only exists inside that function.

def f():
    inside = 1
    print(inside)

f()

Output

1

See: Lesson 21: Modules: ready-made code coming soon

sequence

Running instructions one after another, in order, from the top. The order of the lines is the order things happen.

print("First")
print("Second")

Output

First
Second

See: Lesson 1: What is programming? · Lesson 4: Comments and how Python reads code coming soon

string (str)

A piece of text, inside quote marks: "like this" or 'like this'. Strings can hold letters, numbers, spaces and symbols.

print("A string, with 3 numbers: 123")

Output

A string, with 3 numbers: 123

See: Lesson 1: What is programming? · Lesson 2: print() and strings · Lesson 7: Working with text coming soon

syntax

The rules for how code must be written – like grammar and punctuation for a programming language.

print("Correct syntax")

Output

Correct syntax

See: Lesson 3: Errors are normal

SyntaxError

An error that means the code breaks Python's writing rules, for example a missing bracket, quote mark or colon. Check the line named, and the line above.

print("Hello"
print("Bye")

This example stops with a SyntaxError.

See: Lesson 3: Errors are normal

T

traceback

The full error message Python shows when a program stops. Its last line names the error; the line before gives the line number.

print(nope)

This example stops with a NameError.

See: Lesson 3: Errors are normal

TypeError

An error that means a value is the wrong type for what you're doing with it – for example, joining a string and a number with +.

print("Age: " + 12)

This example stops with a TypeError.

See: Lesson 3: Errors are normal · Lesson 8: Data types and converting coming soon

V

ValueError

An error that means a value is the right type but can't be used – for example, int("hello").

print(int("hello"))

This example stops with a ValueError.

See: Lesson 8: Data types and converting coming soon

variable

A named box that stores a value so your program can remember it and use it later. You create one with = (assignment).

pets = 2
pets = pets + 1
print(pets)

Output

3

See: Lesson 5: Variables: boxes with labels coming soon

W

while loop

A loop that keeps repeating as long as its condition is True. Something inside it must change, or it never stops.

n = 3
while n > 0:
    print(n)
    n = n - 1

Output

3
2
1

See: Lesson 14: while loops coming soon

Python is a registered trademark of the Python Software Foundation. Classfern is independent and is not affiliated with or endorsed by it.

Python course home · Programming Department