1 Star 0 Fork 0

sengluty/learn

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
字符串函数使用举例.py 1.81 KB
一键复制 编辑 原始数据 按行查看 历史
sengluty 提交于 2021-04-07 10:36 . change
mystr='PythonInteresting'
print('字符串字符大小写变换函数示例:')
print('%s lower=%s' % (mystr,mystr.lower()))
print('%s upper=%s' % (mystr,mystr.upper()))
print('%s swapcase=%s' % (mystr,mystr.swapcase()))
print('%s capitalize=%s' % (mystr,mystr.capitalize()))
print('%s title=%s' % (mystr,mystr.title()))
print('字符串格式相关函数示例:')
print('%s ljust=%s' % (mystr,mystr.ljust(20)))
print('%s rjust=%s' % (mystr,mystr.rjust(20)))
print('%s center=%s' % (mystr,mystr.center(20)))
print('%s zfill=%s' % (mystr,mystr.zfill(20)))
print('字符串搜索相关函数示例:')
print('%s find on=%d' % (mystr,mystr.find('on')))
print('%s find t=%d' % (mystr,mystr.find('t')))
print('%s find t from %d=%d' % (mystr,1,mystr.find('t',1)))
print('%s find t from %d to %d=%d' % (mystr,1,2,mystr.find('t',1,2)))
print('%s rfind t=%d' % (mystr,mystr.rfind('t')))
print('%s count t=%d' % (mystr,mystr.count('t')))
print('字符串替换相关函数示例:')
print('%s replace t to *=%s' % (mystr,mystr.replace('t', '&')))
print('%s replace t to *=%s' % (mystr,mystr.replace('t', '&',1)))
print('字符串分隔相关函数示例:')
mynewstr='apple banana orange peach'
print('%s strip=%s' % (mynewstr,mynewstr.split()))
mynewstr='apple;banana;orange;peach'
print('%s strip=%s' % (mynewstr,mynewstr.split(';')))
print('字符串判断相关函数示例:')
print('%s startwith t=%s' % (mystr,mystr.startswith('P')))
print('%s endwith d=%s' % (mystr,mystr.endswith('m')))
print('%s isalnum=%s' % (mystr,mystr.isalnum()))
print('%s isalnum=%s' % (mystr,mystr.isalnum()))
print('%s isalpha=%s' % (mystr,mystr.isalpha()))
print('%s isupper=%s' % (mystr,mystr.isupper()))
print('%s islower=%s' % (mystr,mystr.islower()))
print('%s isdigit=%s' % (mystr,mystr.isdigit()))
strnew='3478'
print('%s isdigit=%s' % (strnew,strnew.isdigit()))
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sengluty/learn.git
git@gitee.com:sengluty/learn.git
sengluty
learn
learn
master

搜索帮助