python common method on the string of

1, capitalize-- the first letter of the string converted to uppercase

a='attention'
b=a.capitalize()
print(b)

2, casefold-- string in all uppercase letters to lowercase letters (uppercase first letter)

a='ABCention'
b=a.casefold()
print(b)

3, lower-- string in all capital letters to lower case letters (including initials)

a='aBCention'
b=a.lower()
print(b)

4, the character is inserted into center-- filled to its set length of the space bar

a='aBCention'
b=a.center(20,'&')
print(b)

 5, subsequence startswith / endwith-- determines what string end, wherein, the control may start and end the start position and end position, wherein the start and end may be empty.

a='aBCention'
b=a.endswith('n')
print(b)

 

6, format-- format, the string value from placeholders alternative

a='aBCention {0} is {1} years old'
b=a.format( 'zhangsan',13)
print(b)

 

 

   NOTE: If the string is not placeholders can be replaced both in the order of occurrence.

a='aBCention {0} is {1} years old'
b=a.format( 'zhangsan',13)
print(b)

 7, format_map-- format, placeholders have been replaced dictionary.

a='aBCention {name} is {age} years old'
b=a.format_map( {'name':'zhangsan','age':13})
print(b)

 

8, index (self, sub, start = None, end = None) - the contents of the index to find the string, wherein, the control may start and end the start position and end position, wherein the start and end may be empty. If the sequence is not found error.
a = 'sadwefda'
b = a.index('f')
print(b)

9, expandtabs () - punctuation, the string may be output in tabular form (containing a string \ t and \ n punctuation to it separately, brackets 30 indicates the length of a space separated)

a = 'sadw\tefda\n*\n&*^^\n*%^$$\tG\tYFYFTYFDT'
b = a.expandtabs(30)   
print(b)

 

10, isalnum () - determines whether a string contains only letters and numbers
a = 'sadw\tefda\n*\n&*^^\n*%^$$\tG\tYFYFTYFDT'
b = a.isalnum()
print(b)

 11, isalpha () - determines whether the character string contains only

a = 'sadYFYFTYFDT'
b = a.isalpha()
print(b)

 

12, isdecimal () / test.isdigit () - determines whether the value of the current variable is a number, the difference between them is isdigit () may be the identification number of different languages, isdecimal () recognized only Arabic numerals

 

test = '01234'
v1 = test.isdecimal()
v2 = test.isdigit()
print(v1,v2)

 

13, swapcase () - converts all characters in a string uppercase
 
test = 'johnny'
v = test.swapcase()
print(v)

 14, islower () - determines whether all characters in a string are lowercase

test = 'johnny'
v = test.islower()
print(v)
15, isnumeric () - determines the genuineness of the digital current string
test = ''
v1 = test.isnumeric()
print(v1)

 

16, isprintable () - determines whether there is a character in the current string is not visible, such as \ t, \ n
= test ' johnny ' 
v = test.isprintable ()
 print (v)

 17, isspace () - determines whether the string is a space full

test = '    '
v = test.isspace()
print(v)
18, istitle () - Analyzing the current string (title) is capitalized
test = 'Johnny is good boy'
v = test.istitle()
print(v)

 19, title () - within the current string (title) the contents of the first letter capitalized

test = 'johnny is good boy'
v = test.title()
print(v)

 

20, join () - each element string according to a specified splicing delimiter
test = 'johnny'
t = ' '
v = t.join(test)
print(v)

 

21, usage of ljust () and the rjust (): the string left justified, right justified output, wherein a character may be transferred fillchar
22, the output character case, upper case (upper), lower case (lower)
23, a different process spaces string, line, or a specified character (lstrip, rstrip, strip)
24, on the use of str.maketrans and translate, str.maketrans can specify the content and character replacement. translate the citation str.maketrans
25, usage of partition, rpartition, split, rsplit of
27, for the use of segmentation, in accordance with The splitlines wrap. True and False whether to retain line breaks
28, on startwish and endwish usage,
29, usage of swapcase () of. Case conversion









 

 

Guess you like

Origin www.cnblogs.com/zhaoqing-cao/p/11621224.html