Python Names and Values
Give values names, recognise their types, and convert user input carefully.
python, variables, types, conversion, input, outputLabels 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
| Value | Type | Meaning |
|---|---|---|
3 | int | Whole number |
2.5 | float | Floating-point number, often approximate |
"3" | str | Text |
True | bool | A true/false value |
None | NoneType | An 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.
