python-list



#List class brackets nested any type index value slice value
v1= "dafd"
# li = [v1,1,23,32,"dsaf",["saf",12,["ddd",23, "123"]],"sdf","ddfa"]
# print(li)
# #Index value delete modification
# print(li[3])
# #Slice, the result of slice is also a list
# print(li[3: -1])
# #for while loop
# for i in range(len(li)):
# print(i,li[i])
# #Modify
# li[1]=1234
# print(li)
#
# #Delete
# del li[0]
# print(li)
# # del li[0:3] #Slice deletion
#
# #Support in operation
# v = 12 in li
# print(v)

li = [v1,1,23, 32,"dsaf",["saf",12,["ddd",23,"123"]],"sdf","ddfa"]
"""
#取值ddd
print(li[5][2][0])
s = "slakghjkaalkgj121324"
li2 = list(s)
print(li2)
# String conversion list new_li=list(s) #List

conversion string

li3 = [12,232,453,234,"1224","akdf"] #The
list contains strings and numbers that can only be spliced ​​with a for loop
s= ""
for i in li3:
s = s + str(i)

print(s)
# If the list has only strings you can use join
li4 = ["sdf","2qwe","123"]
st= "".join( li4)
print(st)

"""
"""
1 cmp(list1, list2)
compares the elements of two lists
2 len(list) the
number of list elements
3 max(list)
returns the maximum value of the list elements
4 min(list)
returns List element min
5 list(seq)
Convert tuple to list
Python contains the following methods:
ordinal method
1 list.append(obj)
appends a new object at the end of the
list 2 list.count(obj)
counts the number of times an element appears in the list
3 list.extend(seq)
Append multiple values ​​from another sequence at the end of the list at once (extend the original list with a new list)
4 list.index(obj)
finds the index position of the first occurrence of a value from the list
5 list.insert (index, obj)
inserts the object into the list
6 list.pop(obj=list[-1])
removes an element in the list (the last element by default) and returns the value of the element
7 list.remove(obj)
moves except the first occurrence of a value in the list
8 list.reverse()
reverses the elements in the list
9 list.sort([func])
sorts the original list
10 list.

"""
# li = [v1,1 ,23,32,"dsaf",["saf",12,["ddd",23,"123"]],"sdf","ddfa"]
#def append(self, p_object): # append list elements
# li = li. append("adfga")

# def clear(self): # clear the list
# li2 = [232,"23re"]
# li2. clear()
# print(li2)

# def copy(self):# Shallow copy
# v = li.copy()
# print(v)
# def count(self, value): # Count the number of elements in the list
# vi = li.count(12)
# print(vi)

# def extend(self, iterable): # Iterable object, loop append to add list element
# li = [11,22,33,11,44,56,"das"]
# li.extend(["23r",998,"sb"])
# print(li)
# li.extend("too Ok")
# print(li)



# def index(self, value, start=None, stop=None): # Get the current value index position according to the value (left first)

# def insert(self, index, p_object): # Specify the index position to insert the value
li = [11,22,33,11,44,56,"das"]


# def pop(self, index=None): # Bubble to delete list elements, delete an element by default, get Deleted element value
li = [11,22,33,11,44,56,"das"]
v = li.pop() #delete the last one by default
v2 = li.pop(3) #specify index


# def remove( self, value): # delete the specified value from the list (left first)
li.remove(33)
print(li)
# def reverse(self): # reverse the current list
print(li.reverse())
# def sort(self, key=None, reverse=False): # sort
print(li.sort())
#print(li. sort(reverse=True))

#cmp
#key

print(min(li))
print(max(li) ) #The
list is sorted and elements can be modified

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326378169&siteId=291194637