博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
字符串操作
阅读量:7124 次
发布时间:2019-06-28

本文共 1568 字,大约阅读时间需要 5 分钟。

字符串不能够修改 name ='my name is sunhao'print(name.capitalize())   #首字母大写 输出:My name is sunhao
print(name.count("m"))     #统计m出现次数 输出:2
print(name.center(50,'-')) #打印50个字符把name放中间 输出:----------------my name is sunhao-----------------
print(name.endswith('ao')) #判断一个字符串是否以ao结尾
输出:True
print(name.find('name')) #查找name,找到返回其索引,找不到返回-1 输出:3 print(name[name.find('name'):])输出:name is sunhao name_info='my name is {_name} and i am {_age} old'  #format可以这样用 print(name_info.format(_name='sunhao',_age=18))输出:my name is sunhao and i am 18 oldprint(name_info.format_map({
'_name':'sunhao','_age':20})) #format_map 字典用法输出:my name is sunhao and i am 20 old
print('9aA'.isalnum())  #判断是否包含数字和字母 输出:True print('abA'.isalpha())  #判断是否包含纯英文字符 输出:True
print('123'.isdigit())   #判断是否是整数 输出:True
print('1A'.isidentifier())  #判断是不是合法的变量名 输出:Falseprint('abc'.islower())    #判断是否是小写输出:Trueprint('33a'.isupper())     #判断是否是大写输出:Falseprint('#'.join(['1','2','3']))输出:1#2#3print(name.ljust(50,'*'))   #表示长度50 不够右边*号补上输出:my name is sunhao********************************* print(name.rjust(50,'-'))    #表示长度50 不够左边-号补上输出:---------------------------------my name is sunhaoprint('SUNHAO'.lower())      #大写变小写 输出:sunhaoprint('sunhao'.upper())       #小写变大写输出:SUNHAOprint('SunHao'.lstrip())  #去掉左边空行和回车print('SunHao'.rstrip())  #去掉右边空行和回车print('sunhao'.replace('u','U',1))  #替换1次输出:sUnhaoprint('sunhaoshaoa'.rfind('a')) #找到最右边目标的索引输出:10print('sun test'.split('t'))   #以t切分  t没有了 输出:['sun ', 'es', '']print('Sunhao'.swapcase())     #大小写互换输出:sUNHAO

 

转载于:https://www.cnblogs.com/sunhao96/p/7561630.html

你可能感兴趣的文章
NGINX + PHP FPM 504 502错误
查看>>
大侠们帮帮忙呢,centos服务器老是重启
查看>>
spring远程调用
查看>>
JackSon Json转化异常注意
查看>>
hessianorb c++调用java尝试
查看>>
dva roadhog 1.x 升级 roadhog 2.x 后 沿用 svg 的方法
查看>>
解决resin的org.xml.sax.SAXParseException问题
查看>>
我的友情链接
查看>>
互联神州金牌讲师陈老师工程中debug排错视频
查看>>
JSF页面中使用js函数回调后台bean方法并获取返回值的方法
查看>>
cobbler中ks.cfg文件配置详解
查看>>
shell训练DAY20
查看>>
使用os/exec执行一些高级命令
查看>>
SSh登陆失败的日志查看与***预防
查看>>
得成CMMI大牛
查看>>
Oracle学习(二):编写简单SELECT语句
查看>>
虚拟化技术教程大全
查看>>
Spring Boot 2.x 系列教程:WebFlux REST API 全局异常处理 Error Handling
查看>>
我的友情链接
查看>>
我的友情链接
查看>>