Ainsteinx Logo
Ainsteinx
👤
Welcome to Ainsteinx
Login

Change Language

Currency

Home
Blog
Services
All lessons
EP.8 Python for Laos

f-strings: put variables inside text

name = "ນາງ ແກ້ວ"
price = 125000

print(f"ສະບາຍດີ {name}!")
print(f"ລາຄາ {price:,} ກີບ")
Video coming soon
EP.8 Tips

f-strings: put variables inside text

The trick Python programmers use every day.

Put an f before the opening quote and write variables straight inside { }.

Inside { } you can also calculate and format, e.g. {price:,} adds thousands separators.

ep08-f-strings.py
name = "ນາງ ແກ້ວ"
price = 125000

print(f"ສະບາຍດີ {name}!")
print(f"ລາຄາ {price:,} ກີບ")

Output

ສະບາຍດີ ນາງ ແກ້ວ!
ລາຄາ 125,000 ກີບ
  • #PythonສຳລັບຄົນLaos
  • #Python
  • #ຮຽນໂປຣແກຣມ
  • #ບອກຕໍ່ຄວາມຮູ້
  • #shorts

Watch and share on