014 String: wonderful variety of built-in methods

capitallize capitalized

>>> str1.capitalize()
'I love china'

casefold all lowercase letters

>>> str2 = "ADASF"
>>> str2.casefold()
'adasf'

center (width) centering and padded with spaces to the string length specified

>>> str2.center(20)
'       ADASF        '

Number count (sub [, start [, end]]) elements appear

>>> str1 = "agdssdggssa"
>>> str1.count("s")
4

endswith (sub [, start [, end]]) is not checked in the end sub

>>> str1 = "agdssdggssa"
>>> str1.endswith("sa")
True

extendtabs (tablesize = 8) to \ t replace spaces

>>> str1 = "asdf\taf\tsa\tesf"
>>> str1.expandtabs(tabsize=3)
'asdf  af sa esf'

find () to find the value of the index element

>>> str1 = "agdssdggssa"
>>> str1.find("a")
0
>>> str1.find("w")
-1

Reference small turtle teacher
https://fishc.com.cn/forum.php?mod=viewthread&tid=38992&extra=page%3D1%26filter%3Dtypeid%26typeid%3D403

Published 42 original articles · won praise 0 · Views 296

Guess you like

Origin blog.csdn.net/qq_43169516/article/details/103156472