Reading preferences
Concept

Python Names and Values

Give values names, recognise their types, and convert user input carefully.

python, variables, types, conversion, input, output

Labels for values

A labelled box helps us find what we put away. In Python, a name gives us a way to refer to a value. score = 3 binds the name score to the integer 3. Later score = 5 changes what the name refers to; it does not mean 3 itself changed. Python is case-sensitive: score and Score are different.

Names can contain letters, digits and underscores, but cannot start with a digit or be a reserved word such as if. Choose names that describe their job.

Types and conversion

ValueTypeMeaning
3intWhole number
2.5floatFloating-point number, often approximate
"3"strText
TrueboolA true/false value
NoneNoneTypeAn explicit absence of a value

int("3") converts valid integer text to 3; str(3) turns 3 into text. float("2.5") makes a floating-point value. int("three") raises ValueError; conversions do not magically understand every word.

Python illustration

score = 3
score = score + 2
text = "4"
print(score)
print(int(text) + score)
print(str(score) + text)

Prepared output — not live execution:

5
9
54

+ adds numbers but joins two strings. Here str(score) is "5", so joining it with "4" produces "54", not the number 9.

See the reasoning

Follow the example one step at a time

Follow the names and conversions in the lesson's example. This is a prepared teaching demonstration, not live code execution.

Bind score

score → 3   (integer)

The name score refers to the integer 3.

Ask for input

name = input("Name: ") displays a prompt and reads a line as text. Even if someone types 4, the result is "4" until converted. This site does not ask for or run input; when writing a local program, consider empty or invalid answers and explain errors instead of silently inventing a value. Learn one way to handle errors in text files and exceptions.

Reflect on the concept

Four fixed questions to reinforce the reasoning. Answers are not saved or scored.

1. After score = 3, what does score refer to?
2. How are 3 and "3" different?
3. What kind of value does input return?
4. What happens when int converts text that is not a valid integer?

References and further reading