---restore content starts---
Capitalize () method to capitalize the first letter of the string
# Convert the first letter of a string to uppercase Text = ' Alet 'ret = text.capitalize () print (ret)
Alet
Casefold () method to capitalize the first letter of the string
# converts all uppercase letters of a string to lowercase ' Alet ' = text.casefold ()print(ret)
Alet
Centers A string and fills the Text.center ()
# Set the width and center the content # 10 represents the total length of the string # * represents blank position padding (one character allowed) ' Alex ' = Text.center (+,'*')print(ret)
Count occurrences of characters (' ex ', 1,5)
Text.count (' character to Judge ', ' index of Start position ', ' index of End position ')
# calculate the number of occurrences of a character ' Alexalex ' = Text.count ('ex')print(ret)
2
Determine whether to start with what, ending with StartsWith () EndsWith ()
# decide whether to start with, what to end with ' Alexalex ' startret=text.startswith ('al'= Text.endswith ('ex ')print(Startret,endret)
True True
---restore content ends---
Related methods for the "Python string" string (i)