Python basic data type-string parameters (learning notes), python learning notes
First:
Capitalize (self ):
Example:
A1 = "alex"
Tmp = a1.capitalize ()
Print (tmp)
Output result: Alex
String parameter description: capitalize (), which upper the first letter of the string.
Second:
Center ()
Example:
A1 = "alex"
Tmp = a1.center (20 ,"_")
Print (tmp)
Output result: _______ alex _______
String parameter description: The total length of center () is set to 20 characters, alex is 4, 20 is set, center is left in the center, blank before and after filling ___
Third:
Count ()
Example:
A1 = "alex is algood"
Tmp = a1.count ("al") or tmp = a1.count ("al", 0, 4/10)
Print (tmp)
Output result: the first output result a1 appears twice, and the second result appears once/twice
String parameter description: count () indicates the number of sub-sequences. The number of al records is searched from left to right. You can specify the number of times that al appears from the nth digit to the nth digit, 0, 4 indicates the number of occurrences of the al from the first to the fourth places. Apparently, only one occurrence of the al, 10, 0, and 10 appear from the second to the fourth, and the al appears several times, it appears twice. (Space is also a location)
Fourth:
Enwich ()
Example:
A1 = "hello"
Tmp = a1.endswith ("o ")
Print (tmp)
Output result: True
String parameter description: endswith () determines whether the last word of the string ends with XXX. In this example, we set whether o is the end, which is obviously True. If it is changed to X, obviously, the result is false. We can also specify whether the last one from the nth digit to the nth digit is XX. In this case, tmp = a1.endswith ("0",) is greater than or equal to 0 and smaller than 2. Obviously, the result is False.
Fifth:
Expandtabs ()
Example:
A1 = "hello \ t999"
Print (a1)
Print (a1.expandtabs ())
Print (a1.expandtabs (20 ))
Output result: hello 999
Hello 999
Hello 999
String parameter description: expandtabs (). \ t indicates that internal function conversion is not performed. By default, python automatically converts the tab key to a space and adds \ t to display it as a tab, the first output result is displayed when you click it. The second output result can be pulled to the right, indicating that there are spaces. The third output result can be pulled by 20 spaces.