List
The relationship between lists and variables:
Variables can only have one element, and lists have multiple elements.
It is equivalent to arrays in other languages .
The list also has three attributes: id, type, and value.
lst=['hello',85,55]
print(id(lst))
print(type(lst))
print(lst)
Result display:
List definition method:
- 【】Square brackets
- list()
lst=['hello',85,55]
print(lst)
a=list('hello')
print(a)
Result display:
characteristics of the list:
- List elements are sorted in order
- Only one element of subscript mapping
- Can store duplicate data
- Different types can be mixed
- Dynamically allocate and reclaim memory according to demand
a=list('hello')
print(a)
print(a[0],a[2])
Result display: