Python Basics: Common Strings and an Introduction to Lists
This tutorial note walks through Python variables, demonstrates how lists can store multiple heterogeneous items, explains list declaration, indexing, modification, and shows two ways to iterate over a list with concrete code examples and their output.
This note emphasizes the importance of persistence while introducing Python's handling of strings and lists.
A variable can hold a single value, whereas a list can store multiple values at once using square brackets [].
Key points about lists: the elements may be of different data types; lists are declared with []; individual elements are accessed and modified via zero‑based indexes.
Example code:
name = "张三"
name1 = "李四"
name2 = "王五"
list1 = ["幻影", "兰博基尼", "玛莎拉蒂", "G63", "123", "True", "False"]
print(list1)
# Get element by index (starts at 0)
print(list1[2])
# Modify element by index
list1[2] = "坦克300"
print(list1)
# Iterate over list – method 1
for i in list1:
print(i)
# Iterate over list – method 2
for index, value in enumerate(list1):
print(index, value)The program prints the original list, accesses the third element, updates it, and then prints the modified list. It also demonstrates two iteration styles, producing the full list of elements and their indexes.
Lisa Notes
Lisa's notes: musings on daily life, work, study, personal growth, and casual reflections.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
