Ainsteinx Logo
Ainsteinx
👤
Welcome to Ainsteinx
Login

Change Language

Currency

Home
Blog
Services
All lessons
EP.5 Python for Laos

Lists: many things in one place

cities = ["ວຽງຈັນ", "ຫຼວງພະບາງ", "ປາກເຊ"]
cities.append("ສະຫວັນນະເຂດ")

print(cities[0])
print(len(cities))
Video coming soon
EP.5 Data & structures

Lists: many things in one place

Can one variable hold many items? Yes, with a list.

A list is written with square brackets [ ]. The first item is at position 0, not 1.

Use .append() to add a new item and len() to count how many there are.

ep05-lists.py
cities = ["ວຽງຈັນ", "ຫຼວງພະບາງ", "ປາກເຊ"]
cities.append("ສະຫວັນນະເຂດ")

print(cities[0])
print(len(cities))

Output

ວຽງຈັນ
4
  • #PythonສຳລັບຄົນLaos
  • #Python
  • #ຮຽນໂປຣແກຣມ
  • #ບອກຕໍ່ຄວາມຮູ້
  • #shorts

Watch and share on