#author: Zhouyu
Name = ' My name is Zhouyu '
Print(name.capitalize())
Print(name.count(' m '))
Print(name.center(+,'-'))
Print(name.endswith(' Zhouyu '))
#The above method can be used to determine whether the user entered the mailbox: @qq. com
Print(Name.find(' n '))
#上面这个是去找n的索引, some students may ask what is the use of this, in fact, the characters can be sliced,
Print(Name[Name.find(' n '):8])
Print(Name[Name.find(' n '):])
Information= ' My name is {Username},and I am {age} ', year old. '
Print(Information.format(Username= ' Zhouyu ', age= 22))
#和上面的相比, here's format_map. This can support the dictionary
Print(Information.format_map({' username ': ' Zhouyu ',' age ':12}))
#判断是不是一个只包含数字的字符串.
Print(' a '. isdigit())
#判断是否为小写
Print(' APPLE '. islower())
#判断是否为大写
Print(' Apple '. isupper())
#join是在一个列表中加入你想要的字符如下:
Print(' + '. Join([' 1 ',' 2 ',' 3 '])) #记住, the list must be a string.
#把小写的变成大写的
Print(' Orange '. Upper())
#把大写变成小写
Print(' ORANGE '. Lower())
#去除左边的换行符
Print(' \nzhouyu '. Lstrip())
#去除右边的换行符
Print(' zhouyu\n '. Lstrip())
#去除所有的空格
Print(' zhouyu\n ')
#替换, the default is all replaced, if you just want to replace it can be added after Zhouziqi 1 as follows
Print(' My name is Zhouyu '. replace(' Zhouyu ',' Zhouziqi ', 1))
#分离符split, the default is a space delimiter, this can be separated into a list
Print(' Zhou,zi,qi '. split(', '))
#splitline也是用来分隔的, but it can only break apart line breaks
Print(' Zhouyu\nzhouziqi '. splitlines())
#大小写互换
Print(' Zhouyu love XiaoQiao '. swapcase())
#把一个字符串的每个单词的首字母大写
Print(' Waiting for you '. title())
This article is from "Love Zhou Yu" blog, please be sure to keep this source http://izhouyu.blog.51cto.com/10318932/1964143
Python's Common String functions