Python sequence: String, list, tuples, and python string
Python sequence: String, list, And tuples sequence: a built-in structure function that contains objects in certain order: str () list () tuple () You can use str (obj) the object obj can be converted to the string list (iterj). The inter of the iteratable object can be converted to the list tuple (inter). The inter of the iteratable object can be converted to a tuples. The 2-series slicing OPERATOR: "[]", "[:]", "[:]" For example: >>> x = 'abcde' function len () can calculate the length of x: len (x) = 50 1 2 3 4 positive index-5-4-3-2-1 reverse index positive index is started at 0, at the end of the query, the total length minus 1. The negative index starts from-1 and returns the reverse count from the end, the negative value ending with the total length is 0 1 2 3 4 'a B c d e'-5-4-3-2-1 >>> x [0] 'A' >>> x [4] 'E'> x [-1] 'E'> x [-5] 'A'> len (x) 5 >>> x [1] ==x [-4] True functions: >>> x = list (range (10) >>> x [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> x = tuple (range (10) >>> x (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) member operators: in, not in >>> x = 'abcd' >>>> 'C' in xTrue >>> 'A' not in xFalse this operator is also suitable for the list and metadata built-in operators. function: enumerate () indicates that enumerate is an enumeration and enumerative dictionary. For an iterable/traversed object (such as a list or string ), enumerate forms an index sequence. It can be used to obtain indexes and values at the same time. for example, >>> x = 'abc' >>> for I, t in enumerate (x ):... print (I, t )... 0 a1 b2 c3 d can be used to obtain other functions in the preceding result string operation >>> x = 'abc' >>> x. capitalize () # make the first letter of x 'abc'> x. count ('M', begin, len (x) # Find the number of occurrences of the character 'M' in x> x. find ('M', begin, len (x) # Check whether the 'M' character is in x. If yes, the serial number of the character is returned, no-1> x. endswith ('M', begin, len (x) # Check whether x ends with m. if you add a begin to len (x), check the selected range to determine x. split (str = '') # split x with str as the separator. lstrip () # Remove the left space x. rstrip () # Remove the right space x. strip () # Use both lstrip and rstrip