Type Conversion, online
Six activities your students do on their own devices. See who's finished, and their scores.
Learning
Understanding
Testing
Type Conversion in one minute
What students need to know
The f prefix and curly braces embed the variable value into the string. You can put expressions inside {} and Python evaluates them.
{name} is replaced by the value stored in name. The {} placeholder is replaced by the variable's value.
Mistakes students make
- Line 2 is missing f. Should be: message = f"Hello {name}".
- Line 2 is missing curly braces. Should be: f"I am {age} years old".
- Line 2 uses [ ] instead of { }. Should be: f"Welcome to {city}".
- Line 4 uses (name) instead of {name}. Should be: f"Hello {name}".
PREVIOUS · MODULE 10F-String Formatting
YOU ARE HERE · MODULE 11Type Conversion
NEXT · MODULE 12Comparison Operators
What students will learn in this module
Every question in Module 11
Quick questions
- After
name = "Alice", what isf"Hi {name}"?AHi AliceBHi {name} - After
age = 15, what isf"I am {age}"?AI am 15BI am {age} - What letter starts an f-string?AsBf
- Where do variables go in f-strings?AInside {}BAfter +
- After
city = "Melbourne", what isf"Welcome to {city}"?AWelcome to {city}BWelcome to Melbourne
Key terms
Students type the meaning of:
name = "Alice"f"Hello {name}"age = 15f"I am {age} years old"
Match the pairs
name = 'Bob'
print('Hi {name}')Match it to what it doesage = 10
f'Age: {age'}Match it to what it doesx = 5
f'Value: {x}'Match it to what it doesf'{2 + 2}'Match it to what it doesname = 'Ali'
print(f'Hi {name}!')Match it to what it doesn = 7
print(f'{n} * 2 = {n*2}')Match it to what it doesFill in the blanks
greeting = _"Hello {name}"age = 12 message = f"I am _____ years old"
city = "Sydney" text = f"Welcome to ______"
score = 85 result = f"Your score: {_____}"first = "Jo" last = "Li" full = f"{_____} {____}"
Spot the error
Question 1
Aname = "Alice"Bmessage = "Hello {name}"Cprint(message)
Question 2
Aage = 15Binfo = f"I am age years old"Cprint(info)
Question 3
Acity = "Melbourne"Btext = f"Welcome to [city]"Cprint(text)
Question 4
Afirst = "Bob"Blast = "Smith"Cname = f"{first} {last}"Dgreeting = f"Hello (name)"Eprint(greeting)
Question 5
Ascore = 100Bmessage = f"Score: {score}"Cage = 15Dinfo = "Age: {age}"Eprint(info)
