#value = "raitOrEi"#v = value.capitalize()#首字母大写#print(v)#v1 = v.casefold()#全部变小写,不只是英文的,其他语言特殊的大小写也变换#print(v1)#v2 = v.lower()#只是英文变小写#print(v2)
#设置宽度,并将内容居中#20 代指总长度#只能填充一个字符,字符可有可无,没有字符用空格填充#value = "raitorei"#v = value.center(20)#print(v)#v1 = value.center(20,"*")#print(v1)#v2 = value.ljust(20,"*")#print(v2)#v3 = value.rjust(20,"*")#print(v3)#v4 = value.zfill(20)#只能用0填充#print(v4)
#去字符串中寻找,寻找子序列的出现次数#value = "reraitorei"#v1 = value.count('re')#v2 = value.count('re',5)#v3 = value.count('re',5,6)#起止位置#print(v1)#print(v2)#print(v3)
#encode#decode
#以什么开始#以什么结尾#test = "raitorei"#v = test.startswith('r')#print(v)#v = test.endswith('i')#print(v)
#把字符串中的 tab 符号('\t')转为空格,tab 符号('\t')默认的空格数是 8.#具体规则是,括号里是多少,以这个数字为一组,如果是开头,空格占位数字多少。比如#test = "123\t456789"#v = test.expandtabs()#123 456789 8个一组,空格补缺少的位置#print(v)#v1 = test.expandtabs(6)#123 456789 6个一组,空格补缺少的位置#print(v1)
#从开始往后找,找到第一个之后,获取位置#大于等于开始,小于结束,未找到 -1#test = "rei"#v = test.find('r',0,2 )#print(v)
#index找不到,报错 忽略#test = "rei"#v = test.index('a')#print(v)
#将一个字符串中的占位符替换为指定的值#test = "I'm {name}, age {a}"#print(test)#v = test.format(name='raitorei',a=22)#print(v)
#将一个字符串中的占位符替换为指定的值,字典#test = "I'm {name}, age {a}"#print(test)#v = test.format_map({"name": 'raitorei', "a": 22})#print(v)
#星号 字符串中是否只包含字母,数字,汉字#test = "fdfd1f风动旛动3"#v = test.isalnum()#print(v)
#星号 判断字符串中是否只包含字母,数字,汉字#test = "fdfdf风动旛动"#v = test.isalpha()#print(v)
#判断字符串中是否是数字#test = "123②"#v = test.isdecimal()#②,特殊的不可以#v1 = test.isdigit()#二,中文的数字不支持#v2 = test.isnumeric()#print(v,v1,v2)
#数字 字母 下划线 标识符:def class#test = "a123"#v = test.isidentifier()#数字开头false#print(v)
#数字 字母 下划线 标识符:def class#test = "a123"#v = test.isidentifier()#数字开头false#print(v)
#是否存在不能打印的字符,比如\t,结果是false#test = "a\t123"#v = test.isprintable()#print(v)
#判断是否全部是空格#test = " \t"#v = test.isspace()#print(v)
#判断是否是标题#test = "the loneliest girl"#v = test.istitle()#print(v)#v1 = test.title()#print(v1)#v2 = v1.istitle()#print(v2)
#***** 加入字符#test = "_"#value = "raitorei"#v = test.join(value)#等于"".join(value)#print(v)
#islower() 方法检测字符串是否由小写字母组成。#isupper() 方法检测字符串中所有的字母是否都为大写。#test1 = "abc"#test2 = "abc123"#test3 = "abc123A"#v1 = test1.islower()#v2 = test2.islower()#v3 = test3.islower()#print(v1,v2,v3)#test4 = "ABC"#test5 = "ABC123"#test6 = "ABC123a"#v4 = test4.isupper()#v5 = test5.isupper()#v6 = test6.isupper()#print(v4,v5,v6)
#变换大小写#test = "asdfgh"#v = test.upper()#print(v)#v = v.lower()#print(v)
#默认去除左右空格,\t,\n;可以指定字符#test = " a s fgh "#v = test.lstrip()#print(v)#v = test.rstrip()#print(v)#v = test.strip()#print(v)#v1 = v.strip("h")#print(v1)
#变换大小写#test = "asdfgh"#v = test.maketrans("asd","123")#print(v)#v1 = test.translate(v)#print(v1)
#分割字符,partition包含分隔符,split不包含分隔符#test = "asdfghasdfghasdfgh"#v1 = test.partition("f")#print(v1)#v2 = test.rpartition("f")#print(v2)#v3 = test.split("f",2)#print(v3)#v4 = test.rsplit("f",2)#print(v4)
#分割换行符,默认不包含分隔符(false),true包含分隔符#test = "asdfg\nhasd\nfghasdfgh"#v1 = test.splitlines(True)#print(v1)
#分割换行符,默认不包含分隔符(false),true包含分隔符#test = "asdfg\nhasd\nfghasdfgh"#v1 = test.splitlines(True)#print(v1)
#大小写转换#test = "asdfghJKL"#v1 = test.swapcase()#print(v1)
#替换
test = "asdfghaJKaL"
#v1 = test.replace("a","b")#print(v1)#v2 = test.replace("a","b",2)#print(v2)################基本(7个)#################join#split#find#strip#upper#lower#replace################灰魔法(5个)################
test = "raitorei"
##索引#v1 = test[0]#print(v1)
##切片#v2 = test[0:-1]#print(v2)
##长度#v3 = len(test)#print(v3)#li = [1,2,3,4,5,"123"]#print(len(li))
#循环输出#index = 0#while index < len(test) :#print(test[index])#index += 1#print("---end---")
#for demo in test:#print(a)
#帮助创建数字,可以设置隔多少再创建#v = range(0,100,5)#print(v)#for vv in v:#print(vv)#将输入的文字的索引输出
value = input(">>>")
length=len(value)
num=range(0,length)for f innum:print(f,value[f])#*****注意:
#字符串一且自,不可修改。
#一且修改或者拼接,部会造成重新生成字符串