字符串的函数

#!/usr/bin/evn python
# Aothor Jack
name ="my \tname IS {name},i am {year}"
print(name.capitalize())#大写首字母,中间转为小写
print(name.count("a"))
print(name.center(50,"-"))
print(name.encode())#字符串输出
print(name.endswith("ck"))
print(name.expandtabs(tabsize=30))#jiangTab转换为空格
print(name.find("name"))#找出存储位
print(name.format(name='Jack',year=23))
print(name.format_map( {'name':'jack','year':23} ))#字典
print(name.isalnum())#是否为字母加阿拉伯数字
print(name.isalpha())#纯英文字母
print(name.isdecimal())#判断是否为十进制
print(name.isdigit())#判断是否为int值
print(name.isdigit())#判断是否为int值
print("ab".isidentifier())#判断是否为合法的标识符
print(name.isdigit())#判断是否为int值
print('33A'.isnumeric())#是否为一个数字
print(name.isspace())#判断是否为空格
print(name.istitle())#判断每个单词首字母是否大写
print(name.isprintable())#判断是否能打印tty file drive等不能打印
print(name.isupper())#判断所有是否为大写
print("ax".islower())#判断所有是否为小写

print('+'.join(['1','2','3']))#1+2+3
print(name.ljust(50,'*'))#my name IS {name},i am {year}********************
print(name.rjust(50,'*'))#********************my name IS {name},i am {year}
print('Jack'.lower())#jack
print('Jack'.upper())#JACK
print(' Jack'.lstrip())#去掉左边的空格和回车
print('\n Jack '.rstrip())#去掉右边的空格和回车
print(' Jack '.strip())#去掉左边和右边的空格与回车

p=str.maketrans('abcdef','123456')
print("alex li".translate(p))#1l5x li
print('alex li'.replace('l','L'))#aLex Li
print('alex li'.replace('l','L',1))#aLex Li只替换1个
print('alex li'.rfind('l'))#找到指定字符l的且是最右对的下标
print('alex li'.rsplit())#['alex', 'li']按照默认的空格把字符串分成一个列表
print('alex li lo'.rsplit('l'))#['a', 'ex ', 'i ', 'o']按照指定的字符’l‘把字符串分成一个列表
print('Alex Li'.swapcase())#aLE X lI
print('Alex Li'.zfill(50))#0000000000000000000000000000000000000000000Alex Li
上一篇:Python数据类型(史上最全~不谈)


下一篇:5- Stream-筛选遍历方法