Learn Python 002: String Method

text = 'happy python learning'
print(text.count('n'))
text = text.upper()
print(text)
text = text.capitalize()
print(text)
text = text.title()
print(text + '\n')

text = '    000000happy python learning0000000    '
print(text.strip('0'))
print(text.lstrip('0'))
print(text.rstrip('0'))
print(text.strip())

name = input('What is your name?\n').strip()
#there is another way but not as good:
#print(name.strip())

 

posted @ 2017-07-09 22:46  mxyzptlk  阅读(118)  评论(0)    收藏  举报