python基础入门---字符串常用操作

name = "qjh"
print(name.capitalize())#将首字母大写输出   //Qjh
#print(name.count("q")                   //qjh
#print(name.center(50,"-"))#             //-1
#print(name.endswith("s"))#以什么结尾      
print(name.expandtabs(tabsize=30))#
print(name.find("d"))
print(name.format(name='qjhqqffd'))
print('ad21'.isalnum())
print('ad'.isalpha())
print('1A'.isdecimal())
print('1a'.isdigit())
print(('1A'.isidentifier()))#判断是否是合法的标识符
print('33.33'.isnumeric())
print('my name is '.istitle())
print('my name is '.isprintable())
print('my name is '.isupper())
print('+'.join(['1','2','3']))
print(name.ljust(50,'*'))
print(name.rjust(50,'-'))
print('Qjh'.lower())                  //qjh
print('qjh'.upper())                  //QJH
#print('qjh\n'.lstrip())
#print('\nqjh'.lstrip())
#print('    qjh\n'.strip())
print('---'.lstrip())                 //---
p = str.maketrans("qdsjdsh",'1234567')
print("qjhs".translate(p))           //1476
print('qjjh'.replace('j','J'))      //qJJh
print('qj h'.rfind('h'))           //3
print('q+j+h+d+s+a'.split('s'))   //['q+j+h+d+', '+a']

 

name.capitalize()  首字母大写
name.casefold()   大写全部变小写
name.center(50,"-")  输出 '---------------------Alex Li----------------------'
name.count('lex') 统计 lex出现次数
name.encode()  将字符串编码成bytes格式
name.endswith("Li")  判断字符串是否以 Li结尾
 "Alex\tLi".expandtabs(10) 输出'Alex      Li', 将\t转换成多长的空格 
 name.find('A')  查找A,找到返回其索引, 找不到返回-1 

 

上一篇:10倍性能提升!DLA SQL推出基于Alluxio的数据湖分析加速功能


下一篇:KUBERNETES02_集群安装逻辑、前置环境、搭建一主两从、部署dashboard访问页面(五)