1. Concept library
  2. Python Foundations
  3. Module 1: Values, variables and types

Concept

Type conversion

Turning a value of one type into another on purpose: int("42"), str(3.5), float(user_input). Input from files, forms and the network always arrives as text.

What a session covers

The tutor works through these with you, in conversation and code. A session ends when you have shown them, not when a video does.

  1. Explain why input from files, forms and the network arrives as text
  2. Convert text to int and float on purpose, and a number back to text for output
  3. Predict which conversions raise ValueError and handle one

In practice

A few lines that show Type conversion doing its job.

Python
age_text = input("Age: ")      # always a str
age = int(age_text)
print(age + 1)

print(int(3.99))               # 3, truncates
print(float("2.5") * 2)        # 5.0
print(bool(""), bool("no"))    # False True

The common mistake

Watch for

Calling int() on text that is not a clean integer. int("3.5") and int("") both raise ValueError, so convert through float() or check the text first.

What to know first

Your roadmap puts these before Type conversion, unless you already know them.

How it stays learned

Once a session shows you understand Type conversion, it comes back for review. Each review takes a minute and tells the memory model how well you still know it.

  1. Day 3First recall, while it is fresh
  2. Day 7Second, a week on
  3. Day 18Last, when it has settled
Previous in the module← Variables and assignment