'''
a1 = "alex"
ret = a1.capitalize() #首字母大写
print(ret)
a1 = "alex"
ret = a1.center(20,"*") #输出20个字符,alex居中,其他用*填充
print (ret)
s = "alex is alph"
ret = s.count("al") #在s中al出现的次数
ret2 = s.count("al",0,4) #在s的0到4字节中al出现的次数
print(ret)
print(ret2)
s = "alex is alph"
r = s.endswith("ph") #是否以ph结尾,输出True
ret = s.endswith("l",0,2) #在大于等于0的位置,小于2的位置(就是al),判断是否以l为结尾,输出True
print(ret)
content = "hello\t999" #hello + tab + 999 \t代表tab键
print (content)
print (content.expandtabs())
print (content.expandtabs(20)) #tab键用20个空格代替,expandtabs()括号内为空时用8个空格代替
s = "alex is alph"
print(s.find("ex")) #找到字符串中ex的首字母的位置,输出2,如果找不到返回-1
s = "hello {0},age {1}" #{0}是个占位符
print(s)
new1 = s.format("alex",19) #用alex代替{0},用19代替{1}
print(new1)
s = "alex is alph"
print(s.index("a")) #功能和find一样,找到输出首字母位置,找不到报错退出
s = "alex9"
a = s.isalnum() #检测是否是数字或者字母,是返回True,不是返回False
print (a)
li = ["alex","eric"] #[]表示列表 ()表示元祖
s = "_".join(li) #用_连接列表中的元素
print(s)
s = "alex 1123 alex"
ret = s.partition("123") #以123分割字符串,并放到元祖里
print(ret)
s = "alex 1123 alex"
ret = s.replace("al","DB",1) #从左向右找第一个al并替换成DB
print(ret)
s = "alex 1123 alex"
ret = s.split("e") #用e分割成几个列表,并删除e
print(ret)
s = "AlEx"
print(s.swapcase()) #大写变小写,小写变大写
'''
s = "the school"
ret = s.title() #字符串转换成标题,即首字母大写
a1 = "alex"
ret = a1.capitalize() #首字母大写
print(ret)
a1 = "alex"
ret = a1.center(20,"*") #输出20个字符,alex居中,其他用*填充
print (ret)
s = "alex is alph"
ret = s.count("al") #在s中al出现的次数
ret2 = s.count("al",0,4) #在s的0到4字节中al出现的次数
print(ret)
print(ret2)
s = "alex is alph"
r = s.endswith("ph") #是否以ph结尾,输出True
ret = s.endswith("l",0,2) #在大于等于0的位置,小于2的位置(就是al),判断是否以l为结尾,输出True
print(ret)
content = "hello\t999" #hello + tab + 999 \t代表tab键
print (content)
print (content.expandtabs())
print (content.expandtabs(20)) #tab键用20个空格代替,expandtabs()括号内为空时用8个空格代替
s = "alex is alph"
print(s.find("ex")) #找到字符串中ex的首字母的位置,输出2,如果找不到返回-1
s = "hello {0},age {1}" #{0}是个占位符
print(s)
new1 = s.format("alex",19) #用alex代替{0},用19代替{1}
print(new1)
s = "alex is alph"
print(s.index("a")) #功能和find一样,找到输出首字母位置,找不到报错退出
s = "alex9"
a = s.isalnum() #检测是否是数字或者字母,是返回True,不是返回False
print (a)
li = ["alex","eric"] #[]表示列表 ()表示元祖
s = "_".join(li) #用_连接列表中的元素
print(s)
s = "alex 1123 alex"
ret = s.partition("123") #以123分割字符串,并放到元祖里
print(ret)
s = "alex 1123 alex"
ret = s.replace("al","DB",1) #从左向右找第一个al并替换成DB
print(ret)
s = "alex 1123 alex"
ret = s.split("e") #用e分割成几个列表,并删除e
print(ret)
s = "AlEx"
print(s.swapcase()) #大写变小写,小写变大写
'''
s = "the school"
ret = s.title() #字符串转换成标题,即首字母大写
print(ret)
############################
s = "alex"
# 0=< 0,1 <2
# 切片
print(s[0:2]) #输出数组中的第一二个字母
#while循环
start = 0
while start < len(s):
temp = s[start]
print(temp)
start += 1
#for循环
for item in s: #item作为字符串每次存一个字符
if item == "l":
continue
print(item)