Tag: Action end string Operation Pytho Strip intercept Mat string nbsp
1. Two types of string formatting
String%s number%d
Example Name= ' I am%s '% ' FKK '
Print (name)
' I am FKK '
>>> name= ' I am%s,age%d '% (' daoxin ', +) >>> name ' I am daoxin,age 13 '
The second type:
Index starting from 0, value Index name= ' I am {0},age{1} '
>>> Name.format (' Daoin ', 20)
' I am daoin,age20 '
Intercept string
#左边包含, the right side does not contain
Name= ' Daoxin '
#截取第一个字符串
Print (Name[0])
#从第一个字符开始, intercept two
Print (Name[0:2])
#从第几个字符开始, to the end of the string
Print (name[1:])
#从最后一个开始, intercept the last character
Print (Name[-1]) ==print (len (name)-1)
# #从最后一个开始, intercept all the previous
Print (Name[:-1])
#字符串长度
Print (len (name))
Remove the whitespace method:
Name= ' Daoxin '
#去掉两边空格
Print (Name.strip ())
#去掉左边空格
Print (Name.lstrip ())
#去掉右边空格
Print (Name.rstrip ())
Python string manipulation