The main difference between lists and tuples is that lists can be modified, and tuples cannot be modified. That is, if you want to add elements according to your requirements, the list might be better used. When a sequence cannot be modified, it is more appropriate to use a tuple.
Sequence
Index: Index is the key value of the PHP array. Starting from 0.
Fragmentation: PHP's slice, if number[3:9] Note that the intercepted value starts at the 4th index.
Step size: The stepping length of each operation of the fragment. Can not be 0, to be a negative number, that is, from the back forward.
Sequence addition: Connecting operations using the + number for sequence
Two sequences of the same type can be added.
Multiplying a sequence with a number x will generate a new sequence, and the original sequence will be repeated x times.
None is a python built-in value, and its exact meaning is "nothing" and some language is null.
Membership: Use in to check whether a string exists in a list or string.
Len can check the length of a list or string. PHP uses Str_len and count to check.
List function, which creates lists based on strings. such as list (' Hello ')
Note: You cannot assign values to elements that do not exist in a list location
The Append method is used to append a new object at the end of the list.
The Count method counts the number of times an element appears in the list, such as X.count (1)
The Extend method can append multiple values from another sequence at the end of the list.
The index method finds the indexed position of the first occurrence of a value from the list.
The Insert method is used to insert an object into the list.
The Pop method removes the data from the list, and the default is the last one.
The Remove method removes the first occurrence of a value in the list. Pop is Operation Key,remove is operation value
Reverse the elements in the list backwards.
The sort method sorts the elements in the list.
The sort method does not return a list after it is sorted. So to get a sorted list, you first assign x to Y, and then you sort the Y.
The sort advanced sort provides two parameters, the first of which is that you must specify a function to use in the sort process, and the second is the bool value in reverse order
META Group
Tuples, like lists, are also a sequence. The only difference is that tuples cannot be modified.
Tuples are most often enclosed in parentheses. For example (1,2,3), the sequence is enclosed by square brackets.
If you want to implement a tuple that includes only one value, you must also add a comma, such as (23,)
Tuple function: Takes a sequence as a parameter and converts it to a tuple.
Whether a tuple is fragmented or a tuple. Just like a list fragment or a list.
Test procedure
The code is as follows |
Copy Code |
The length of the element in the #选出数组 (list below) is between 3-6 A=[12,3,4,4,5,5555,556,3,6,6,211111,334456778,23,45] N=0 M=0 B=[0 for I in Range (1,len (A) +1)] #生成相同元素的列表 C=[0 for I in Range (1,len (A) +1)] #生成相同元素的列表 #C =[0,0,0,0,0,0,0,0,0,0,0,0,0,0] #B =[0,0,0,0,0,0,0,0,0,0,0,0,0,0] For n in range (len (A)): B[n]=len (str (a[n)) If B[n]>=3 and b[n]<=6: C[n]=b[n] M+=1 Else C[n]=0 The number of elements that print ' satisfies the condition is: ', m print ' The length list for each element in the list is: ', C #获取每个元素的长度 |