Night 16: Name tags
이미 Python 또는 의사 코드로 이날의 학습을 마쳤습니다. 두 언어 모두에서 완료한 것으로 인정됩니다. 원하면 다시 연습하세요.
이 페이지는 최신 브라우저(SharedArrayBuffer 지원)가 필요합니다. Chrome, Edge, Firefox 또는 Safari를 최신 버전으로 업데이트해 주세요.
English
Tonight: name tags
- Your pet wants a name tag. Tonight you put values inside text.
- You will learn one thing: f-strings.
Words for tonight
| Word | Meaning |
|---|---|
| f-string | a text with an f in front; values can go inside it |
| braces | the brackets { } |
| space | the empty character between words |
English
Values inside text
- Put
fbefore the first quote. Then write variable names inside{ }.
name = "Kit"
age = 2
print(f"{name} is {age} years old")
- Python puts each value where its braces are.

English
Commas or an f-string?
| Code | Output |
|---|---|
print(snack, ":", price) |
apple : 3 |
print(f"{snack}: {price}") |
apple: 3 |
- Commas always add a space. In an f-string you choose the spaces.
English
Maths inside the braces
- Python works out what is inside
{ }first.
age = 2
print(f"Next year: {age + 1}")
print(f"In dog years: {age * 7}")
English
Do not forget the f
- Without
f, the braces are just normal text:
name = "Kit"
print("{name} is sleepy")
print(f"{name} is sleepy")
- Now make some name tags!
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
Read a name, then an age with int(input()). Use an f-string to print Kit is 2 years old.
출력을 보려면 '실행'을 클릭하세요.
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
Read a snack and a price. Print a price tag like apple: 3 coins. There is no space before the :.
출력을 보려면 '실행'을 클릭하세요.
난이도 2/5 · 140코인 + 오늘 첫 완료 시 작은 보너스 추가
Read a name and an age. Print Next year Kit is 3. Work out age + 1 inside the { }.
출력을 보려면 '실행'을 클릭하세요.
난이도 3/5 · 200코인 + 오늘 첫 완료 시 작은 보너스 추가
Read a name, a kind and a number of nights. Print a 3-line card: Name: Kit, then Kind: fox, then Nights: 12/30.
출력을 보려면 '실행'을 클릭하세요.