Python study notes (10-12) array

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:

  1. append use
list1=['alex','xiaowu','xiaomei','malimo']
print(list1)
# 向列表添加元素
list1.append('marry')#append可以加入1个元素
print(list1)

Here Insert Picture Description

list1=['alex','xiaowu','xiaomei','malimo']
print(list1)
list1.append(['marry','bob'])
print(list1)

Here Insert Picture Description
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)

Here Insert Picture Description
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)

Here Insert Picture Description
Remove elements from the list

list1=['aa','bb','cc']
print(list1)
list1.remove('cc')
print(list1)

Here Insert Picture Description

list1=['aa','bb','cc']
print(list1)
temp=list1.pop(1)
print(temp)
print(list1)

Here Insert Picture Description

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)

Here Insert Picture Description

list1=['aa','bb','cc','dd']
print(list1)
temp=list1[:]
#相当于是复制了这个列表
print(temp)
print(list1)

Here Insert Picture Description

List of Operators

  1. Comparison operators

Here Insert Picture Description
If there are multiple elements in the list, then only compare the size of the first element.
Here Insert Picture Description
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

Here Insert Picture Description

  1. Repetition operator
list1=['a','b']
list2=list1*3
print(list1)
print(list2)

Here Insert Picture Description

  1. Membership operator

    To determine whether the elements in the list
    Here Insert Picture Description
    list there are many methods you can use to view dirq go
    Here Insert Picture Description
    after these methods side by side learn it

Published 75 original articles · won praise 45 · views 7317

Guess you like

Origin blog.csdn.net/hahahahhahha/article/details/104176571