The chapter in short
Python is a popular, beginner-friendly programming language with simple, readable syntax. It is used for websites, data science, artificial intelligence and automation.
The chapter covers writing and running Python programs, variables and data types, input and output, operators and expressions, comments, and converting between types.
ProgramInterpreterVariableData typeStringOperator
Key points
- Python is interpreted: each line is translated and run in turn.
- A variable stores a value; Python works out its type, such as int, float, str or bool.
- print() shows output; input() reads text typed by the user.
- Convert input to numbers with int() or float() before doing arithmetic.
- Arithmetic operators: + − * / // (whole division) % (remainder) ** (power).
- A # starts a comment, which Python ignores.
Definitions
- 1
Program
A set of instructions written for a computer to carry out.
- 2
Interpreter
Software that translates and runs a program one line at a time.
- 3
Variable
A named location in memory that stores a value.
- 4
Data type
The kind of value a variable holds, such as integer, float, string or Boolean.
- 5
String
A sequence of characters, written in quotes.
- 6
Operator
A symbol that performs an operation on values, such as + or ==.
- 7
Syntax error
A mistake in the rules of the language that stops a program from running.
Formulas
Reading a number
n = int(input("Enter a number: "))
Arithmetic operators
7 // 2 = 3; 7 % 2 = 1; 2 ** 3 = 8