🐍 Python From Zero — 02/13: Variables & Data Types
Posted on: November 14, 2026
Description:
A program needs to keep track of information. In this lesson, we’ll give values names, inspect their types and update a small learner profile.
1. Give a value a name
learner = "Asha"
print(learner) # Asha
print("learner") # learner
= assigns the value on the right to the name on the left. A variable name refers to a value; quotes create literal text. Use a name only after assigning it.
2. Meet four common types
learner = "Asha"
lessons = 3
study_hours = 1.5
is_complete = False
| Type | Purpose | Example |
|---|---|---|
str |
Text | "Asha" |
int |
Whole numbers | 3 |
float |
Floating-point numbers | 1.5 |
bool |
True/false values | False |
Strings use matching single or double quotes. Write booleans as True or False, with the capital letter and no quotes. "False" is text. Floats can represent fractional values, but many decimal fractions are stored approximately.
3. Inspect the types
print(type(learner)) # <class 'str'>
print(type(lessons)) # <class 'int'>
print(type(study_hours)) # <class 'float'>
print(type(is_complete)) # <class 'bool'>
type() reports the type of the value. The word class is part of Python’s output; you do not need to learn classes yet. Python does not require a type declaration for these assignments.
4. Update your profile
learner = "Maya"
study_hours = 2.0
is_complete = True
lessons = lessons + 1
print(learner, lessons, study_hours, is_complete)
Output:
Maya 4 2.0 True
Python evaluates the right-hand side before assigning the result. So lessons = lessons + 1 reads 3, computes 4, then updates what lessons refers to. Commas let print() display multiple items, separated by spaces by default.
Names are not permanently tied to one type: Python allows reassignment to a different type. Keep each name’s meaning consistent so your program stays easy to follow.
5. Quotes matter
print(3 + 1) # 4
print("3" + "1") # 31
The first expression adds integers. The second joins strings. Mixing them with 3 + "1" raises TypeError; Python does not automatically choose a conversion for you.
Use descriptive names such as study_hours. For beginner-friendly names, use letters, digits and underscores, start with a letter or underscore, and avoid Python keywords such as class. Names are case-sensitive: learner and Learner are different. Avoid replacing built-in names such as print or type.
Your turn
Create a profile with all four types. Print it, update each value and print it again. Save as variables.py, then use IDLE’s Run → Run Module, as in lesson 1. No extra packages are needed.
Takeaway: names refer to values, values have types, and assignment changes what a name refers to.
Next lesson: Working with Numbers.
Code Snippet:
None
No comments yet. Be the first to comment!