单引号表示string
spam = "That is Alice's cat."
print(spam)
双引号表示string
spam = "say hi to Bob's mother"
print (spam)
原始的string(Raw String)
print(r"That is Alice\'s cat")
三括号表示的string
print('''
hi alice
How are you?''')
得到大写形式
spam = spam.upper()
得到小写形式
spam = spam.lower()
print("How are you?")
feeling = input()
if feeling.lower() == 'great':
print('I feel great too.')
else:
print('I hope the rest of your days are good!')
isX
spam.islower()
spam.isupper()
spam.isalpha()
spam.isalnum()
spam.isdecimal() # only numerical strings
spam.isspace()
spam.istitle()
以某个字符创开始或者结尾
spam.startswith('df')
spam.endswidth('df')
连接字符串
','.join(['a', 'b', 'c'])
拆分字符
'My name is Simon'.split()
spam.split('\n')
对其和居中
'hello'.rjust(10, '*')
'hello'.ljust(10, '*')
'hello'.center(10, '=')
去除收尾特定的字符
'hello'.lstrip()
'hello'.lstrip()
'hello'.strip(' abc ')
最后编辑于 :2018.05.13 20:35:17
©著作权归作者所有,转载或内容合作请联系作者 【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。 平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。