def capitalize (self):
str = ' age '
Print (Str.capitalize ())
Result: Age
Conclusion: The first letter is capitalized, the other letters are lowercase
def casefold (self):
str = ' Age-age '
Print (Str.casefold ())
Results: Age-age
Conclusion: The first letter is capitalized, the other letters are lowercase
Def center (self, Width, fillchar=none):
str = ' Age-age '
Print (Str.center (20, ' = '))
Results: ======age-age=======
Conclusion: The string str is placed in a 20-length character, and the missing Fillchar characters are used to populate
def count (self, sub, Start=none, End=none):
str = ' Age-age '
Print (Str.count (' AG '))
Print (Str.count (' AG ', 5,6))
Results: 1, 0
Conclusion: Count the number of occurrences of a particular character in a string, or you can specify a starting position
def encode (self, encoding= ' utf-8 ', errors= ' strict '):
str = ' Chian '
Print (Str.endswith (' an ', 3,5))
Result: True
Conclusion: Returns whether a string ending with a specific character can be specified as the starting position
def expandtabs (self, Tabsize=none):
str = "\talex"
Print (Str.expandtabs ())
Print (Str.expandtabs (10))
Results: Alex/alex
Conclusion: The default Tab key is 8 spaces, plus a space with numbers as digits
def find (self, sub, Start=none, End=none):
str = "Alex is a Workhard man"
Print (Str.find (' is '))
Print (Str.find (' or ', 4,13))
Results: 5/11
Conclusion: To find a character in a string, you can specify the starting character
def format (*args, **kwargs):
def index (self, sub, Start=none, End=none):
str = "Alex is a Workhard man"
Print (Str.index (' is '))
Results: 5
Conclusion: To find character positions in a string, you can specify the starting character
def isspace (self):
#-*-Coding:utf-8-*-
str = ' fa '
Print (Str.isspace ())
Result: False
Conclusion: strings are required to be empty strings
def istitle (self):
str = "This is String Example ... Wow!!! "
Print (Str.istitle ())
str = "This is string EXAMPLE....WOW!!!"
Print (Str.istitle ())
Results: True/false
Conclusion: Only the first letter is capitalized is the title
def join (self, iterable):
str = "This is String Example ... Wow!!! "
Print (': '. Join (str))
STR1 = [' This ', ' was ', ' a ', ' book ']
Print (': '. Join (STR1))
STR2 = (' This ', ' was ', ' a ', ' book ')
Print (': '. Join (STR2))
STR3 = {' 1 ': ' This ', ' 2 ': ' Was ', ' 3 ': ' A ', ' 4 ': ' Book '}
Print ('-'. Join (STR3))
Results:
T:h:i:s:: i:s:: s:t:r:i:n:g:: e:x:a:m:p:l:e:.:.:.:w:o:w:!:!:!
This:is:a:book
This:is:a:book
2-4-1-3
Conclusion: Connect the characters with a connector.
def ljust (self, Width, fillchar=none):
STR1 = ' This was a book '
Print (Str1.ljust (20, ' # '))
Result: This is a book######
Conclusion: Left-justified, the default padding character is empty
def maketrans (self, *args, **kwargs):
Import string
str1 = ' ABCDE '
Map = Str1.maketrans (' abcde ', ' 12345 ')
Print (Type (map))
Print (map)
Results:
<class ' Dict ' >
{97:49, 98:50, 99:51, 100:52, 101:53}
Conclusion: ASCII a-97,1-49
def partition (self, SEP):
Import string
str = "http://www.w3cschool.cc/"
Print (Str.partition ('///'))
Result: (' http: ', '//', ' www.w3cschool.cc/')
Conclusion: Three strings are returned, left is the left side of the delimiter, the right side is the delimiter to the right, and the middle is the divider
def replace (self, old, new, Count=none):
str = "http://www.w3cschool.cc//"
Print (Str.replace ('//', ' $$ ', 1))
Print (Str.replace ('//', ' $$ ', 2))
Results: http:$ $www. w3cschool.cc// http:$ $www. w3cschool.cc$$
Conclusion: replace these old characters with new ones
def rfind (self, sub, Start=none, End=none):
str = "Hello,alex,alpha"
Print (Str.rfind (' al ', 5,13))
Results: 11
Conclusion: Find the rightmost character and return the index number
str = "Line1-a b c d e f\nline2-a b c\n\nline4-a b c D";
Print (Str.splitlines ())
Print (str.splitlines (0))
Print (Str.splitlines (3))
Print (Str.splitlines (4))
Print (Str.splitlines (5))
Results:
[' Line1-a b c d E F ', ' line2-a b C ', ', ' line4-a b c d ']
[' Line1-a b c d E F ', ' line2-a b C ', ', ' line4-a b c d ']
[' Line1-a b c d e f\n ', ' line2-a b c\n ', ' \ n ', ' line4-a b c d ']
[' Line1-a b c d e f\n ', ' line2-a b c\n ', ' \ n ', ' line4-a b c d ']
[' Line1-a b c d e f\n ', ' line2-a b c\n ', ' \ n ', ' line4-a b c d ']
Conclusion: Returns a list containing the rows as elements
Python STR Internal Function Introduction