Dictionaries: look things up by name
words = {"ໝາ": "dog", "ແມວ": "cat", "ນົກ": "bird"}
print(words["ແມວ"])
words["ປາ"] = "fish"
print(len(words))
Dictionaries: look things up by name
Look up Lao → English translations with a dict.
dict ເກັບຂໍ້ມູນເປັນຄູ່ key: value ພາຍໃນວົງເລັບ { }. ເອີ້ນຄ່າດ້ວຍ key ແທນທີ່ຈະໃຊ້ຕຳແໜ່ງ.
ເໝາະກັບຂໍ້ມູນທີ່ມີຊື່ ເຊັ່ນ ລາຄາສິນຄ້າ ຫຼື ເບີໂທຂອງໝູ່.
words = {"ໝາ": "dog", "ແມວ": "cat", "ນົກ": "bird"}
print(words["ແມວ"])
words["ປາ"] = "fish"
print(len(words))
ຜົນລັບ
cat 4
- #PythonສຳລັບຄົນLaos
- #Python
- #ຮຽນໂປຣແກຣມ
- #ບອກຕໍ່ຄວາມຮູ້
- #shorts
Watch and share on
ຮຽນຕໍ່
Lists: many things in one place
cities = ["ວຽງຈັນ", "ຫຼວງພະບາງ", "ປາກເຊ"]
cities.append("ສະຫວັນນະເຂດ")
print(cities[0])
print(len(cities))
Lists: many things in one place
Can one variable hold many items? Yes, with a list.
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.