Chapter One: simple data types and variables

String:

Use of the modified string case

Use .title () alterations to the first letter of each word in a string to uppercase

= A " ASD dfsdf " 
Print (a.title ()) 
Results of: 
Asd Dfsdf

Use the + string concatenation

a = "shen"
b = "yile"
c = a + " " + b
print(c.title())
执行结果:
Shen Yile

Use tabs \ t and newline \ n add a space

a = "shen"
b = "yi\tle"
c = a + "\n" + b
print(c.title())
执行结果:
Shen
Yi    Le

Use rstrip, lstrip, the end of the strip deleted, at the beginning, and the beginning of the trailing spaces

Doubt: the middle of the string box how to remove?

Use str () function to avoid the type of error

age = 23
message = "Happy " + str(age) + "rd Birthday!"
print(message)
执行结果:
Happy 23rd Birthday!

 

Guess you like

Origin www.cnblogs.com/sxdpython/p/12591691.html