Lists

Dicts

Tuples

Lists

Intro to list

Untitled

friend1 = "Mike"
friend2 = "Josh"
friend3 = "Jerry"
print(f"{friend1}, {friend2}, {friend3} are my friend")
# Mike, Josh, Jerry are my friend

friendList = ["Mike", "Josh", "Jerry"]
print(f"{friendList[0]}, {friendList[1]}, {friendList[2]} are my friend")
# Mike, Josh, Jerry are my friend
# 與loop配合使用

Untitled

friendList = ["Mike", "Josh", "Jerry"]
print(len(friendList))
# 3
luckyNumbers = [3, 6, 9, 11, 17, 26, 31]
print(luckyNumbers[-1]) # 31
print(luckyNumbers[0:3]) # [3, 6, 9]
print(luckyNumbers[::2]) # [3, 9, 17, 31]
print(luckyNumbers[::-1]) # [31, 26, 17, 11, 9, 6, 3]
x = [1, 2, 3, 1, 3, 1, 1]
print(x.count(1)) # 4
print(x.index(1)) # 0