Common Operations List Python learning (2) of the list

### 1.append: Add at the end of the list elements 
#
# Fruits = [ 'the Apple']
# fruits.append ( 'Banana')
# Print (Fruits)

### 2.count: statistics an element appears in the list number

# TEMP = [ 'to', 'BE', 'or', 'Not', 'to', 'BE']
# temp.count Result = ( 'BE')
# Print (Result)

### Extend : Add a list to another list element

# a = [l, 2,3]
# B = [ 'a', 'B', 'C']
# a.extend (B)
# Print (a )

### index: the index to find the first position in the list of the first occurrence of a certain value, if not found, an exception is thrown

# a = [ 'a', 'b', 'c' ]
# a.index index = ( 'a')
# Print (index)


### iNSERT: the values into a list of a location

# a = [ 'a', 'b', 'hello', ' C ']
# a.insert (. 3,' World ')
# Print (A)

### POP: remove the last element in the list, and returns the value of that element

# A = [1,2,3,4]
# a.pop TEMP = ()
Print # (TEMP)
# Print (A)

### Remove: removing the first element in the list of matches, it does not return value of this element is removed.
If the removed ### value does not exist in this list, it will throw an exception

# A = [ 'A', 'C', 'E', 'T', 'E']
# a.remove ( 'E')
# Print (a)

### reverse: the elements of the list stored in the reverse, changes the value of the original list

# a = [1,2,3,4,5,6,7,8, ]
# a.reverse ()
# Print (a)

### Sort: a sorted list of elements (according to ascii code: a-zA-Z or numbers: minus infinity to infinity), changes the original list value

# A = [4,5,2,4,5,7]
# a.sort ()
# Print (A)

# A = [ 'A', 'R & lt', 'Y', 'I', 'Q ']
# a.sort ()
# Print (A)

# A = [4,5,8,1]
# B = the sorted (A)
# Print (A)
# Print (B)

### del: the subscript to remove elements
# a = [ 'a', 'e', 'f', 'y'




A = # [ 'A', 'E', 'F', 'Y']
# IF '. 3' in A:
# Print (True)
# the else:
# Print (False)

### List: the other data type (may be iterated) into a list

# = a 'World'
# Print (list (a))

Guess you like

Origin www.cnblogs.com/godblessmehaha/p/11094818.html