in thePythonLearning, we all know that the list is one of the most commonly used data types, and certainly one of the must-learn content., it can appear as a comma-separated value within a square bracket. What this article shares with you is Python.list data types and related operations, I want to contact the firstpythonchildren's shoes help,pythonveteran please automatically jump off this article. each element in the list is assigned a number-its location, or index, the first index is0, the second index is1, and so forth. the list of operations that can be performed includes indexing, slicing, adding, multiplying, and checking members. in addition,PythonThe method for determining the length of the sequence and determining the maximum and minimum elements has been built in. A list's data items do not need to have the same type to create a list, as long as the different data items separated by commas are enclosed in square brackets. is as follows: List1 = [' Physics ', ' H2O ', 1997, 2000]list2 = [1, 2, 3, 4, 5]list3 = ["A", "B", "C", "D"]slicing operations on a list: L[0:2] take the first to second element of a list L[2:5] take the third to fourth element of a list L[::2] interval takes list elements 1,3,5 .... the common operations of the list are as follows: Li=[' Day ', ' Eric ', ' Rain ']calculates the list length and outputs PrintLen(Li)) 3append elements to the list"Seven" Li. Append ("seven")in the list,1insert elements in a single position"Tony" Li. Insert (0, "Tony")Modify List Section2elements of the location are"Kelly" LI[1] = "Kelly"remove an element from a list"Eric" Li. Remove ("Eric")Remove the list from the2an element Li. Pop (1)Remove the list from the2to4an element forI in range (3): Li.Pop(1)reverses all elements of the list #Method1 li[::-1]#Method2 List (Reversed (LI))UseFor,Len,Rangethe index of the output list is usedenumratethe output list element and ordinal (ordinal from -start) forKvinchEnumerate (li, 100): Print (k, v)UseForall elements of the loop output list forI inRange(Len (LI)): Print (i) Source: Network
Python Learning list data types and general operations