← Learning Hub
PythonFREE IN BOTH LANGUAGESLesson 01 / 12

Variables, values & types

Name your data, inspect its type, and avoid common beginner mistakes.

Download notes (.md)

Downloads are text notes. Choose Save as PDF in your browser’s print dialog for a PDF copy.

Understand the concept

A variable is a name bound to an object. In score = 10, score refers to an integer object. Python does not require a type declaration; type(score) tells you the current object’s type. Reassigning score changes what the name refers to.

Use int for whole numbers, float for decimal approximations, str for text, and bool for True or False. Quotes distinguish text from a number: "10" is a string, while 10 is an integer. input() returns text, so convert deliberately with int() or float() when a calculation needs a number.

Use meaningful names such as lessons_completed. Assignment uses =; comparison uses ==. Converting invalid text, such as int("hello"), raises ValueError. Validate user input instead of assuming every entry is numeric.

Run the example

name = "Ashu"
lessons_completed = 3
total_lessons = 12
progress = lessons_completed / total_lessons * 100
print(type(lessons_completed).__name__)
print(f"{name}: {progress:.0f}% complete")

Output / what to expect

int
Ashu: 25% complete

Try it yourself

Create price = 49.0 and quantity = 3. Calculate and print the total. What changes if price is "49.0" instead?

View a suggested solution
price = 49.0
quantity = 3
print(price * quantity)  # 147.0
text_price = "49.0"
print(float(text_price) * quantity)  # 147.0

Reference: Official documentation ↗

Make it yours.

Run the example and attempt the exercise before marking this lesson complete.

pass the idea on

What did this make you think?

You review and publish the post yourself. Instagram uses your device’s share menu when available; otherwise copy the text and link. Facebook opens the link composer, where you add your thoughts.