# replace 替换 text = 'xiaomafafafahaoyunlianlian' v = text.replace('fa','shun') x = text.replace('fa','shun',1) print(v) print(x) xiaomashunshunshunhaoyunlianlian xiaomashunfafahaoyunlianlian
断句:expandtabs( number)
name = "nihao" # isalpha()字符串中是否只包含字母 v = name.isalpha() print(v)
number = '123456' # isalnum() 字符串中是否只包含数字 v = number.isalnum() print(v)
# isspace() 判断是否都是空格 name = ' ' v = name.isspace() print(v)
# istitle() 判断是否是标题(首字母大写) test = 'Ni Hao zhong guo' v = test.istitle() print(v) test = 'Ni Hao Zhong Guo' v = test.istitle() print(v)
# join 将字符串中的每一个元素按照指定分隔符进行拼接 test = '你是风儿我是沙' m = "*" v = m.join(test) print(v) 你*是*风*儿*我*是*沙
# center() 中间填充 test = '好好学习' v = test.center(20,'*') print(v) ********好好学习********
# ljust() 向右填充 test = '好好学习' v = test.ljust(20,"*") print(v) 好好学习****************
# rjust() 向左填充 test = '好好学习' v = test.rjust(20,"*") print(v) ****************好好学习
# zfill() 固定向左以0填充 test = '好好学习' v = test.zfill(20) print(v) 0000000000000000好好学习
# islower() 判断是否全部是大写 # lower() 转换为大小写 test = 'Majun' v1 = test.islower() v2 = test.lower() print(v1,v2) False majun
# lstrip() 去除左边的空格 name = ' majun ' v = name.lstrip() print(v) majun
# rstrip() 去除右边的空格 name = ' majun ' v = name.rstrip() print(v) majun
# strip() 去除两边的空格 name = ' majun ' v = name.strip() print(v) majun