s = str(input ("请输入字符串!:"))
print(s.replace(" ",""))
运行截图:
s = str(input ("请输入字符串!:"))
count = 0
for i in s:
if 0x4E00 <= ord(i) <= 0x9FA5:
count+=1
print(count)
运行截图;
s = str(input ("请输入字符串!:"))
print("转换为大写为:")
print(s.upper())
print("转换为小写为:")
print(s.lower())
运行截图:
s = str(input ("请输入字符串!:"))
ls = []
ls = s.split(",")
for i in ls:
print(i)
运行截图:
print("原列表为:")
ls = ["1 1 1 1 1", "2 2 2 3 4 4 5 6 " ]
print(ls)
for i in ls:
print(i.replace(" ",""))
运行截图:
s = str(input ("请输入字符串!:"))
print("这个书的书名长度为:%s"%len(s))
运行截图:
s = str(input ("请输入字符串!:"))
ls = list(s)
ls.sort()
for i in ls :
print (i,end=" ")
运行截图:
s = str(input ("请输入字符串!:"))
ls = []
ls = s.split(" ")
for i in range(len(ls)-1,-1,-1):
print(ls[i],end=" ")
运行截图:
s = str(input ("请输入字符串!:"))
ls = list(s)
for i in range(0,len(ls)):
if ls[i]=="呵":
print(i+1)
运行截图:
print("原列表为:")
ls = ["0000", "1111111","2222222222","33333333","444444444" ,"5555555555","66666666666","777777","8888888888","99999999999"]
print(ls)
for i in range(0,10):
if len(str(ls[i]))>10:
ls1 = list(ls[i])
for j in range(0,8):
if j ==7:
print(ls1[j])
else:
print(ls1[j],end="")
if len(str(ls[i]))<=10:
print(ls[i])
运行代码:
s = str(input ("请输入字符串!:"))
ls = list(s)
a = 0
for i in range(0,len(ls)-1):
if (ord(ls[i]) == ord("呵")) and (ord(ls[i+1]) == ord("呵")):
print(i+1)
运行代码:
s = str(input ("请输入字符串1!:"))
s1 = str(input ("请输入字符串2!:"))
a = s.count(s1)
b = s1.count(s)
if a !=0:
print("字符串2是字符串1的子串")
if b !=0:
print("字符串1是字符串2的子串")
if a==b==0:
print("相互不包含")
运行截图:
s = str(input ("请输入字符串s!:"))
s1 = str(input ("请输入字符串是s1!:"))
ls = list(s)
ls1 = list(s1)
p = 0
if len(s)>=len(s1):
for i in ls1:
for j in ls:
if j==i:
p+=1
if p>=1:
print("s1包含于s中")
else:
print("不满足题目")
if len(s1)>=len(s):
for i in ls:
for j in ls1:
if j==i:
p+=1
if p>=1:
print("s包含于s1中")
else:
print("不满足题目")
运行截图:
s = str(input ("请输入字符串!:"))
ls = list(s)
for i in range(0,len(ls)):
if ls[i]=="1" or ls[i]=="2" or ls[i]=="3" or ls[i]=="4" or ls[i]=="5" or ls[i]=="6" or ls[i]=="7" or ls[i]=="8" or ls[i]=="9":
ls[i]=""
for i in ls:
print(str(i),end="")
运行代码:
s = str(input ("请输入字符串!:"))
ls = list(s)
for i in range(0,len(ls)):
if ord(ls[i])>128:
ls[i]=""
for i in ls:
print(str(i),end="")
运行代码:
s = str(input ("请输入字符串!:"))
ls = list(s)
p = 0
for i in range(0,len(ls)):
if ord(ls[i])>=57 and ord(ls[i])<=128:
p+=1
if p>=1:
print("满足题目!")
else:
print("不满足题目!")
运行代码: