Magic string entry of python (a)

1.test="alex"

   v=test.capitalize()

   print (v) // output capitalized

2.test1="alex"

   v1=test1.center(20,"#")

    print (v1) // living intermediate output string, the space is filled by a # character, may not be filled

3.test2="alexalex"

   v2=test2.count("a",0,5)

   print (v2) // output 2, a character string starting from the 0 position to occur before the fifth

4.test3="ALEX"

   v3 = test3.casefold ()

   print (v3) // output is alex, pay attention to it and lower () the difference, lower () for the ASCII code, casefold () it applies to all national language

5.test4="alex"

   v4=test4.endswith("ex")

   print (v4) // output is a logic value True

Guess you like

Origin www.cnblogs.com/cxydnxs/p/12123021.html