Chapter 4: Variables and Constants
Complete Python lesson for very beginners. Technical words are explained in simple language, and every outline topic includes a practical example, expected output, steps, and practice.
Chapter Overview
This Python tutorial chapter covers Variables and Constants through 15 connected topics. Work through the examples in order, check the expected output, and complete the practice after each topic.
- 4.1 Creating Variables
- 4.2 Assignment
- 4.3 Variable Names
- 4.4 Naming Rules
- 4.5 Multiple Assignment
- Plus 10 additional Python topics in this chapter.
4.1 Creating Variables
Creating Variables is part of Variables and Constants. In simple language, it means a name that refers to a value.
It is one building block of variables and constants and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.
Python / Practical Example
name = "Ava"
age = 20
print(name, age)Expected Output
Ava 20Step-by-Step Explanation
- Read the example from top to bottom.
- Identify the value, object, or operation related to this topic.
- Change one small input and predict the result before running it.
4.2 Assignment
Assignment is part of Variables and Constants. In simple language, it means a Python idea used while learning variables and constants.
It is one building block of variables and constants and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.
Python / Practical Example
name = "Ava"
age = 20
print(name, age)Expected Output
Ava 20Step-by-Step Explanation
- Read the example from top to bottom.
- Identify the value, object, or operation related to this topic.
- Change one small input and predict the result before running it.
4.3 Variable Names
Variable Names is part of Variables and Constants. In simple language, it means a name that refers to a value.
It is one building block of variables and constants and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.
Python / Practical Example
name = "Ava"
age = 20
print(name, age)Expected Output
Ava 20Step-by-Step Explanation
- Read the example from top to bottom.
- Identify the value, object, or operation related to this topic.
- Change one small input and predict the result before running it.
4.4 Naming Rules
Naming Rules is part of Variables and Constants. In simple language, it means a Python idea used while learning variables and constants.
It is one building block of variables and constants and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.
Python / Practical Example
name = "Ava"
age = 20
print(name, age)Expected Output
Ava 20Step-by-Step Explanation
- Read the example from top to bottom.
- Identify the value, object, or operation related to this topic.
- Change one small input and predict the result before running it.
4.5 Multiple Assignment
Multiple Assignment is part of Variables and Constants. In simple language, it means a Python idea used while learning variables and constants.
It is one building block of variables and constants and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.
Python / Practical Example
x, y = 10, 20
print(x)
print(y)Expected Output
10
20Step-by-Step Explanation
- Two values appear on the right.
- Python assigns them by position.
- Each name receives one value.
4.6 Unpacking Values
Unpacking Values is part of Variables and Constants. In simple language, it means a Python idea used while learning variables and constants.
It is one building block of variables and constants and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.
Python / Practical Example
x, y = 10, 20
print(x)
print(y)Expected Output
10
20Step-by-Step Explanation
- Two values appear on the right.
- Python assigns them by position.
- Each name receives one value.
4.7 Reassignment
Reassignment is part of Variables and Constants. In simple language, it means a Python idea used while learning variables and constants.
It is one building block of variables and constants and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.
Python / Practical Example
value = 10
print(type(value).__name__)
value = "ten"
print(type(value).__name__)Expected Output
int
strStep-by-Step Explanation
- Bind a name to an integer.
- Reassign the same name to text.
- The name can refer to objects of different types over time.
4.8 Dynamic Typing
Dynamic Typing is part of Variables and Constants. In simple language, it means a Python idea used while learning variables and constants.
It is one building block of variables and constants and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.
Python / Practical Example
value = 10
print(type(value).__name__)
value = "ten"
print(type(value).__name__)Expected Output
int
strStep-by-Step Explanation
- Bind a name to an integer.
- Reassign the same name to text.
- The name can refer to objects of different types over time.
4.9 Object References
Object References is part of Variables and Constants. In simple language, it means a value with data and behavior.
It is one building block of variables and constants and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.
Python / Practical Example
name = "Ava"
age = 20
print(name, age)Expected Output
Ava 20Step-by-Step Explanation
- Read the example from top to bottom.
- Identify the value, object, or operation related to this topic.
- Change one small input and predict the result before running it.
4.10 Variable Identity
Variable Identity is part of Variables and Constants. In simple language, it means a name that refers to a value.
It is one building block of variables and constants and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.
Python / Practical Example
a = []
b = a
c = []
print(a is b)
print(a is c)Expected Output
True
FalseStep-by-Step Explanation
- b refers to the same list as a.
- c is a different empty list.
- is checks object identity, not equal contents.
4.11 id()
id() is part of Variables and Constants. In simple language, it means a Python idea used while learning variables and constants.
It is one building block of variables and constants and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.
Python / Practical Example
value = [1, 2]
print(type(id(value)).__name__)Expected Output
intStep-by-Step Explanation
- Create an object.
- id() returns an identity number for that object during its lifetime.
- The example prints the type of that identity value instead of depending on a machine-specific number.
4.12 Constants by Convention
Constants by Convention is part of Variables and Constants. In simple language, it means a value you intend not to change.
It is one building block of variables and constants and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.
Python / Practical Example
name = "Ava"
age = 20
print(name, age)Expected Output
Ava 20Step-by-Step Explanation
- Read the example from top to bottom.
- Identify the value, object, or operation related to this topic.
- Change one small input and predict the result before running it.
4.13 Deleting Variables
Deleting Variables is part of Variables and Constants. In simple language, it means a name that refers to a value.
It is one building block of variables and constants and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.
Python / Practical Example
name = "Ava"
age = 20
print(name, age)Expected Output
Ava 20Step-by-Step Explanation
- Read the example from top to bottom.
- Identify the value, object, or operation related to this topic.
- Change one small input and predict the result before running it.
4.14 Scope Introduction
Scope Introduction is part of Variables and Constants. In simple language, it means the part of a program where a name is available.
It is one building block of variables and constants and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.
Python / Practical Example
name = "Ava"
age = 20
print(name, age)Expected Output
Ava 20Step-by-Step Explanation
- Read the example from top to bottom.
- Identify the value, object, or operation related to this topic.
- Change one small input and predict the result before running it.
4.15 Variable Best Practices
Variable Best Practices is part of Variables and Constants. In simple language, it means a name that refers to a value.
It is one building block of variables and constants and helps you write clearer, more predictable Python programs. For a very beginner, focus first on what goes in, what Python does, and what comes out; details become easier after you run a small example.
Python / Practical Example
name = "Ava"
age = 20
print(name, age)Expected Output
Ava 20Step-by-Step Explanation
- Read the example from top to bottom.
- Identify the value, object, or operation related to this topic.
- Change one small input and predict the result before running it.
Common Beginner Mistakes
- Copying code without predicting what each line does.
- Ignoring the first useful error message or traceback location.
- Mixing tabs/spaces or changing indentation accidentally.
- Using data of the wrong type for an operation.
- Trying to learn many advanced variations before mastering one small working example.
Chapter Practice
- Choose three topics from this chapter and re-type their examples without copying and pasting.
- For each example, change one input and predict the output first.
- Explain five technical terms from this chapter in your own beginner-friendly words.
- Create one small program that combines at least two chapter topics.
- Keep notes about errors you made and what fixed them.
Mini Project / Challenge
Create a small Python exercise that combines at least three ideas from Variables and Constants. Start with a tiny working version, test it, then improve it one step at a time.
- Choose three topics from this chapter.
- Write or adapt a small Python example using those topics.
- Predict the output before running the code.
- Test at least one different input.
- Write two sentences explaining what the program does and what you learned.
20 Questions & Answers
1. What is the main goal of Chapter 4?
The goal is to understand variables and constants through small explanations, examples, and practice.
2. Should I memorize every command or method?
No. Understand the pattern, practice the common form, and learn how to read documentation when you need exact details.
3. Why are the examples small?
Small examples isolate one idea at a time, which makes errors easier to understand and fix.
4. What should I do when an example gives an error?
Read the last part of the traceback, check spelling and indentation, confirm the required package or file exists, and compare the input types with what the operation expects.
5. Why should I predict output before running code?
Prediction forces you to reason about the program instead of only copying it.
6. What should I remember about Creating Variables?
Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.
7. What should I remember about Assignment?
Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.
8. What should I remember about Variable Names?
Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.
9. What should I remember about Naming Rules?
Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.
10. What should I remember about Multiple Assignment?
Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.
11. What should I remember about Unpacking Values?
Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.
12. What should I remember about Reassignment?
Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.
13. What should I remember about Dynamic Typing?
Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.
14. What should I remember about Object References?
Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.
15. What should I remember about Variable Identity?
Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.
16. What should I remember about id()?
Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.
17. What should I remember about Constants by Convention?
Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.
18. What should I remember about Deleting Variables?
Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.
19. What should I remember about Scope Introduction?
Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.
20. What should I remember about Variable Best Practices?
Remember its beginner meaning, the problem it helps solve, the shape of a small example, and one common situation where it is appropriate.