f-strings: put variables inside text
name = "ນາງ ແກ້ວ"
price = 125000
print(f"ສະບາຍດີ {name}!")
print(f"ລາຄາ {price:,} ກີບ")
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.
name = "ນາງ ແກ້ວ"
price = 125000
print(f"ສະບາຍດີ {name}!")
print(f"ລາຄາ {price:,} ກີບ")
Output
ສະບາຍດີ ນາງ ແກ້ວ! ລາຄາ 125,000 ກີບ
- #PythonສຳລັບຄົນLaos
- #Python
- #ຮຽນໂປຣແກຣມ
- #ບອກຕໍ່ຄວາມຮູ້
- #shorts
Keep learning
Your first program: print()
print("ສະບາຍດີ ລາວ!")
print("ຂ້ອຍກຳລັງຮຽນ Python")
Your first program: print()
Write your first program in a single line!
Variables: boxes for your data
name = "ສົມພອນ"
age = 20
height = 1.68
print(name, age, height)
Variables: boxes for your data
A variable is a labelled box that can hold anything.
if / else: let your program decide
age = 17
if age >= 18:
print("ລົງທະບຽນໄດ້")
else:
print("ຍັງນ້ອຍຢູ່")
if / else: let your program decide
How does a computer make decisions? With if.
for loops: repeat without retyping
for i in range(1, 6):
print("ຮອບທີ", i)
for loops: repeat without retyping
Count from 1 to 5 with a single line of logic.