# ---str, int, float, bool is invariant
s = "hello"
print(s.upper())
print(s)
s = s.upper() # need to set the value
print(s)
# ---list, dict is variant
shopping_list = ['mouse', 'keypad']
shopping_list.append('screen') # can change the value directly, then there is shopping_list = ['mouse', 'keypad', 'screen']
shopping_list = []
shopping_list.append("mouse")
shopping_list.append("keypad")
shopping_list.append("screen")
shopping_list.remove("keypad")
shopping_list[0] = 'ram-device'
print(shopping_list)
price_list = [700, 899, 2000, 688]
max_price = max(price_list)
min_price = min(price_list)
sort_price = sorted(price_list)
print(max_price)
print(min_price)
print(sort_price)
# 列表可以嵌套
a = ['a', 'b', 'c']
n = [1, 2, 3]
x = [a, n]
print(x) # [['a', 'b', 'c'], [1, 2, 3]]
print(x[0]) # ['a', 'b', 'c']
print(x[0][1]) # b
python入门 --- list
于 2023-06-04 09:39:11 首次发布