- Slice, index, number of characters
name = " AITG " # Span style= "COLOR: #008000" > output t print (name[2 ]) # output ait print (Name[0:3 # output 4 print (Len ( Name)
- First letter Case
" AITG " Print (Name.capitalize ())
- All Letters lowercase
" AITG " Print (Name.capitalize ()) # Output: AITG Print (Name.lower ()) # Output: AITG
- Set the width and center the content
name = " AITG " print (Name.center ( " # " # output: # # # aitg###
- go to the string and look for the number of occurrences of the subsequence
name = Span style= "COLOR: #800000" > " AITGAITGAITG " print (Name.count ( " a " # output 3 times print (Name.count ( " a " , 0,7 # find 0-7-bit (does not contain 7th digit) occurrences # output 2 times
- find string beginning with | end
name = " AITG " Span style= "COLOR: #000000" > Find the character ending with print (Name.endswith ( " g " # Span style= "COLOR: #0000ff" >print (Name.startswith ( " a " # output result: False or True
- string according to \ t segmentation
name = " name\tmail\tpass\nname\tmail\tpass\nname\tmail\tpass " print (Name.expandtabs (10 # by \ t segmentation # output # name Mail pass # name Mail pass # name Mail pass
- Find where a string first appears
" AITG " Print (Name.find ("t")) # look back from the beginning, find the first string, the output gets the position # Output 2
#未找到输出结果-1
- format the string.
" I am {a}, age {b} " # Specifies the incoming Print " AITG ", B = +))# Dictionary method incoming print(Name.format_map ({"A "'aitg'"b": 27}))
- Whether the string contains letters and numbers
name = " AITG " Span style= "COLOR: #008000" ># output True print (Name.isalnum ()) # output False print ( " Span style= "COLOR: #800000" >ait g\t ". Isalnum ())
-
name = " AITG " output True print ( Name.isalpha ()) print ( " yards farming is crazy " .isalpha () Output False print ( " 1234 " . Isalpha ())
- current input is a number
# support 10-digit judgment print (" 1234324 " .isdecimal ()) supports 10 binary and 10 decimal print (" 1234①⑨ " .isdigit ()) supports 10 digits, 10 decimal, Kanji digit print ( " twos 1234①⑨ " .isnumeric ()) # output True
- Whether there are non-visible characters/t/n
" aitg\t\n " Print (Name.isprintable ()) # output False does not appear true
- Determine if all are spaces
" " Print (Name.isspace ()) # all are spaces return true no person False
-
name = " my name is AITG "" Span style= "COLOR: #008000" ># # output False print (Name.istitle ()) # Convert to title format # output My Name is AITG print (Name.title ())
- Stitching each element in a string according to the specified delimiter
" AITG " Print ("_". Join (name)) # Output A_i_t_g
- determine if all are case and converted to uppercase and lowercase letters
#determine if all lowercase letters arePrint('AITG'. Islower ())#determine if the letters are all uppercasePrint('AITG'. Isupper ())#Convert all letters to lowercasePrint('AITG'. Lower ())#convert all letters to uppercasePrint('AITG'. Upper ())
- remove specified string
# You can specify the removal character, with a limited number of matches. name = AITG " # default remove space to the left \ n print (Name.lstrip ()) # The default removes the space on the right \ \ n print (Name.rstrip ()) # default removes spaces on both sides \ \ n print (Name.strip ())
- corresponding relationship substitution
" AITG " Print (Name.replace ("g""g")) # Output AITG
- Split String
Name ="AITGAITG"#The default is divided into three parts#from left to rightPrint(Name.partition ("T"))#from right to leftPrint(Name.rpartition ("T"))#split the specified number from left to rightPrint(Name.split ("T", 1))
- Case conversion (uppercase and lowercase conversions in letters)
" AITGAITG " Print (Name.swapcase ()) # Output AITGAITG