Learning theme: an array of
learning Date: 2020-02-04
Python Version: 3.7.4
An array is put only one type of data (int-type or a float)
The list can put all types of things. (Mixed place, strings, numbers, etc.).
So to speak, the list is a broad array of content can be mixed placement.
#创建一个空列表
emptylist=[]
Add an element to the list:
- append use
list1=['alex','xiaowu','xiaomei','malimo']
print(list1)
# 向列表添加元素
list1.append('marry')#append可以加入1个元素
print(list1)
list1=['alex','xiaowu','xiaomei','malimo']
print(list1)
list1.append(['marry','bob'])
print(list1)
2. extend the use
to join the two elements would have to extend the use of
list1=['alex','xiaowu','xiaomei','malimo']
print(list1)
list1.extend(['marry','bob'])
print(list1)
3. insert of use
list1=['alex','xiaowu','xiaomei','malimo']
print(list1)
#把 baby放在第一位,记住第一位是0.
list1.insert(0,'baby')
print(list1)
Gets the element from the list
list1=['aa','bb','cc']
temp=list1[1]
print(temp)
Remove elements from the list
list1=['aa','bb','cc']
print(list1)
list1.remove('cc')
print(list1)
list1=['aa','bb','cc']
print(list1)
temp=list1.pop(1)
print(temp)
print(list1)
Note that the above has been used to the concept of object-oriented, object-oriented action list is the concept of a method, such as insert, pop, etc. are some methods list.
List slice (slice)
list1=['aa','bb','cc','dd']
print(list1)
temp=list1[2:]
print(temp)
print(list1)
list1=['aa','bb','cc','dd']
print(list1)
temp=list1[:]
#相当于是复制了这个列表
print(temp)
print(list1)
List of Operators
- Comparison operators
If there are multiple elements in the list, then only compare the size of the first element.
If a string, you can compare, it is more the size of their ASIC code.
2. Logical Operators
3. Link operator
list1=[1,2]
list2=[3,4]
list4=list1+list2
- Repetition operator
list1=['a','b']
list2=list1*3
print(list1)
print(list2)
-
Membership operator
To determine whether the elements in the list
list there are many methods you can use to view dirq go
after these methods side by side learn it