python learning 8 (list)

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:
Insert picture description here

List definition method:

  1. 【】Square brackets
  2. list()
lst=['hello',85,55]
print(lst)
a=list('hello')
print(a)

Result display:
Insert picture description here
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:
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_40551957/article/details/114237393