标签:cap logs 格式化 方法 iss 连接 sid 空格 字符串
.capitalize
name = "my \tname is {name} and i am {year} old" print(name.capitalize())#首字母大写 My name is {name} and i am {year} old
.count
name = "my \tname is {name} and i am {year} old" print(name.count("a"))#字符串里面包含几个"a" 5
.center
name = "my \tname is {name} and i am {year} old" print(name.center(50,"-"))#打印50个字符如果不够用-补全 ------my name is {name} and i am {year} old------
.endswith
name = "my \tname is {name} and i am {year} old" print(name.endswith("ex"))#判断字符串是以什么结尾 False
.expandtabs
name = "my \tname is {name} and i am {year} old" print(name.expandtabs(tabsize=30))#将tab转换成多少个空格 my name is {name} and i am {year} old
.find
name = "my \tname is {name} and i am {year} old" print(name[name.find("name"):])#字符串name所在的索引值,同时可以用来切片 name is {name} and i am {year} old
.format
name = "my name is {name} and i am {year} old" print(name.format(name=‘alex‘,year=23))#格式化输出 my name is alex and i am 23 old
.format_map
name = "my name is {name} and i am {year} old" print(name.format_map({‘name‘:‘alex‘,‘year‘:12}))#如果格式化,导入的是字典,可以用format_map方法,结果跟format一样。 my name is alex and i am 12 old
.isalnum
name = "" print(name.isalnum())#如果 name 至少有一个字符并且所有字符都是字母或数字则返回 True,否则返回 False False name = "ads12" print(name.isalnum())#如果 name 至少有一个字符并且所有字符都是字母或数字则返回 True,否则返回 False True
.isdigit
name = "my name is big long" print(name.isdigit())#判断字符串只包含数字则返回 True 否则返回 False False print("22".isdigit())#判断字符串只包含数字则返回 True 否则返回 False True
.isidentifier
print(‘a‘.isidentifier())#判断是不是一个合法的标识符 True
.isspace
print("33".isspace())#判断是不是空格 False print(" ".isspace())#判断是不是空格 True
.istitle
print(‘My Name Is ‘.istitle())#判断字符串首写字母是不是大写
.join
>>> print(‘+‘.join([‘1‘,‘2‘,‘3‘]))#用于将序列中的元素以指定的字符连接生成一个新的字符串。 1+2+3
标签:cap logs 格式化 方法 iss 连接 sid 空格 字符串
原文地址:http://www.cnblogs.com/fsdl1988/p/7367476.html