Use string object and slice

Cited live content quoted string is called: the symbol can be double quotes, single quotes, three marks.

String object common method

capitalize: Let string initial capital letters.

 

 

 

 center so that the string center, a space filled with default.

count: Statistics string, number or a character string that appears

 

 encode: specify the code parameter, a string into bytes (byte decode method)

 

 

 

 

Slice character in the string 'xxx' and Unicode strings u'xxx 'may be regarded as a list, each element is a character. Thus, the string may be a slice operation, but the operation is still the result string. In many programming languages, it offers a lot of variety for a string interception function, in fact, the purpose is to string sections. Python is not taken for the function string, only a slice slicing operation can be completed (Slice) may acquire sub-string (part of a string) from a string. We use the square brackets, starting offset start, termination end offset step and optional steps to define a slice.

The operation can be completed slicing operation (Slice) may acquire sub-string (part of a string) from a string. We use the square brackets, starting offset start, termination end offset step and optional steps to define a slice.  

   [:] Extracted from the beginning (default position 0) to the end (the default position -1) of the entire string            

 [Start:] extracted from the start to the end           

  [: End] extracted from the beginning to end - 1           

  [Start: end] extracted from the start to the end - 1          

   [Start: end: step] extracted from the start to the end - 1, each step extracting a left character position of the first character / offset 0, the right of the last character position / offset is -1 the following is a string type and output formats  

  | - ljust () # Left   

 | - rjust () # right justified   

 | - count () # statistics string, number or a character string that appears  

  | - decode Method encode / # of bytes specified by the coding parameter string into bytes (must master) 

   | - endswith # judge the string is not in the end xxx 

   | - startswith # what began  

  | - find # and index the same way as the characters find difference is that the query does not exist, returns -1  

  | - rfind # Find last  

  | - index # query string or character index position in the string   

 | - rindex # Find last  

  | - format # format string, recommended  

  | - isalnum # judge only the string of numbers and letters  

  | - isalpha # judge the string is not only letters 

   | - isdigit # judge is not a string of numbers  

  | - isdecimal # judge is not a string of numbers   

 | - islower # judge is not all lowercase string  

  | - isupper # judge the string is not all uppercase   

 | - istitle # judge is not title  

  | - isspace # judge is not a space   

 | - join # string concatenation   

 | - split # accordance with specific symbols split the string, the result is a list of  

  | - lower # the string converted to lowercase letters  

  | - upper # the string of letters are converted to uppercase  

  | - strip # Clear clear space   

 | - rstrip # Clear a space on the right 

   | - lstrip # Clear a space on the left   

Guess you like

Origin www.cnblogs.com/wananluni/p/11521222.html