首页 > 编程语言 > 详细

python中str的常用方法汇总

时间:2019-09-30 15:09:27      阅读:104      评论:0      收藏:0      [点我收藏+]
a = strABC

# Strabc  : 首字母大写,其他全部小写
b = a.capitalize()
print(b)

# STRABC  : 全部大写
c = a.upper()
print(c)

# strabc  : 全部小写
d = a.lower()
print(d)

# STRabc    大小写翻转
e = a.swapcase()
print(e)

# Abc Edf_Ghi*Jkl.Mno,Pqr,Stu(Vw)Xy4Z    以非英文字母隔开的首字母大写
a = "abc edf_ghi*jkl.mno,pqr,stu(vw)xy4z"
b = a.title()
print(b)

# #######python#######     (宽度,填充物(默认空格)) 字符居中
str = "python"
str1 = str.center(20,"#")
print(str1)

# abc     def
# a       def   当字符串中出现tab时,用空格补充满tab 8位的倍数,使得后续字符对齐
str = "abc\tdef"
str1 = "a\tdef"
str2 = str.expandtabs()
str3 = str1.expandtabs()
print(str2)
print(str3)

 

python中str的常用方法汇总

原文:https://www.cnblogs.com/aiworld/p/11612772.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!