String built-in functions --str (object)

 
STR 
Test = ' Alex ' 
# ## initials 
V1 = test.capitalize ()
 # ## lowercase all modifications, caseflod more Niubi many unknown strain lowercase 
V2 = test.casefold () 
V3 = test.lower ( )
 Print (V1, V2, V3)
 # ## set the width and center the contents 
V4 = test.center (20 is, ' * ' )
 Print (V4)
 # ## to find the number of sequence strings appear 
v5 test.count = ( ' E ' , 1,6 )
 Print (V5)
 # ## determines whether the end of the specified sequence (beginning), returns False True 
V6 = test.endswith ( ' X' ) 
V6_1 = test.startswith ( ' X ' )
 Print (V6)
 Print (v6_1)
 # ## Looking sequence (interval can be specified), and return to find the first position, if not returned -1 
V7 = test.find ( ' EX ' , l, 4 )
 # ## if no error will 
v17_1 test.index = ( ' EX ' , l, 4 )
 Print (V7, v17_1)
 # # pass keyword value (formatted placeholders ) 
Test = ' to pass the string values {0} Image {} Image 1 ' 
V8 = test.format (keyword = 0 ' - Image by value ' , keyword 1 = ' - equals sign ' )
V9Test.format_map = ({ ' Image 0 ' : ' - Incoming dictionary ' , ' Image 1 ' : ' - mapping dictionary elements ' })
 Print (V8, V9)
 # # pass in order of position values (formatted placeholder) 
Test = ' the position passed by value 0} {, {}. 1 ' 
V10 = test.format ( ' first position 0 ' , ' second positions. 1 ' )
 Print (V10) 

# ## determines the character it just string of letters or numbers 
Test = ' alex123 ' 
V11 = test.isalnum ()
 Print (V11)

# ## Tabs \ T 
Test = ' name \ temail \ tpassword \ nalax \ [email protected] \ TSDF ' 
V12 = test.expandtabs (15 )
 Print (V12) 

# ## contains only letters 
Test = ' asdsf ' 
V = test.isalpha ()
 Print (V) 

# ## determines whether a numeric string 
Test = ' ' 
V1 = test.isdecimal () 
V2 = test.isdigit ()
 # # Chinese determination value 
Test = ' two ' 
V3 = test.isnumeric ()
 Print(v1, v2, v3)
 # ## contains characters not display 
the Test = ' isPrintable \ nfalse ' 
v = test.isprintable ()
 Print (v) 

# ## whether all the space 
the Test = ' isspace Space ' 
v = the Test .isspace ()
 Print (V) 

# ## and determines whether the title is converted to the title 
Test = ' the Return True The iF iS A String String title-cased, False otherwise. ' 
V1 = test.istitle () 
V2 = test.title () 
v3 = test.istitle ()
 Print (v1, v2, v3) 

### string concatenation 
Test = ' with the specified character string concatenation element \ n- ' 
V1 = '  ' .join (Test) 
V2 =   ' _ ' .join ([ ' mosaic ' , ' string ' ])
 Print (V1, V2) 

'' ' 
with the specified character string concatenation element 
 splicing string _ 
' '' 


# ## specified width - fill 
Test = ' specified width - filling ' 
V1 = test.ljust (20 is, " # " ) 
V2 = Test. rjust (20, " * ") 
v3Test.center = (20 is, " @ " ) 
V4 = test.zfill (20 is )
 Print (V1)
 Print (V2)
 Print (V3)
 Print (V4)
 '' ' 
specified width - filling ######## ##### 
************* specified width - filling 
@@@@@@ specified width - filling @@@@@@@ 
0000000000000 specified width - filling 
'' ' 

# ## lowercase lowercase whether --- 
Test = ' the Return of The Copy String A Converted to lowercase. ' 
V1 = test.islower () 
V2 = test.lower ()
 Print (V1)
 Print (V2)
 '' ' 
False
The String A Copy of return Converted to lowercase. 
'' ' 
# # --- determines whether all uppercase capitalize, uppercase lowercase change - change uppercase to lowercase 
Test = ' the Return True String The IF IS AN UPPERCASE String, False otherwise. ' 
V1 = test.isupper () 
V2 = test.upper () 
V3 = test.swapcase ()
 Print (V1)
 Print (V2)
 Print (V3)
 ' '' 
False 
the RETURN THE STRING the IF TRUE UPPERCASE the IS STRING the AN, the OTHERWISE FALSE . 
RETURN THE STRING the IF TRUE UPPERCASE the IS STRING the AN, the OTHERWISE FALSE. 
'' ' 

# ### processing space \ n-\ T 
Test = '  \ n processing \ t spaces \ t remove pointing character ' 
V1 = test.rstrip ( ' character ' ) 
V2 = test.lstrip ( ' character ' ) 
V3 = test.strip ( ' character ' )
 Print (V1)
 Print (V2)
 Print (V3)
 '' ' 
 processing space ## to the right processing space \ \ t n 
processing space ## left processing space \ n \ t 
process space ## around the processing space (space between the strings without the processing elements) ' 
'' 

# Alternatively correspondence relation ## 
Test = ' correspondence relationship, maketrains, replacement character, Translate ' 
m = test.maketrans ( 'Establishing correspondence between the characters to be replaced' , ' A correspondence relationship corresponding to the establishment of alternative character ' ) 
V = test.translate (m)
 Print (V)
 ' '' 
correspondence relationship, maketrains, substituted for the corresponding character, Translate 
'' ' 

# ### divided strings, 
Test = ' find a first specified element dividing \ 3 minutes of N_ into ' 
V1 = test.partition ( ' points ' ) 
V2 = test.rpartition ( ' points ' ) 
V3 = test.split ( ' points ' , 2)   # # # default all found, but no delimiter, looking after a specified number of times, split left to right a specified number 
v4 = test.  splitlines (True) # ## can only be divided according to a newline, whether to retain newline \ n (True)
Print (V1)
 Print (V2)
 Print (V3)
 Print (V4)
 '' ' 
(' the first to find a specified elements ',' sub ',' cut \ divided into 3 points of N_ ') 
(' first found dividing the specified element \ of N_ into 3 '' points '' ') 
[' find the specified elements ',' cut \ of N_ ',' to 3 minutes '] 
[' find the specified elements segmentation \ n ',' _ divided into 3 '] 
' ''

 

Guess you like

Origin www.cnblogs.com/liuhuacai/p/11353694.html