1.
s = "hhhh hh hh"
print(s.replace(" ",""))
#去掉字符串所有的空格-----将空格替换为空
2.
s = "长路漫漫zzz"
print(s.count("漫"))
#获取字符串中汉字的个数
3.
s = "Hello,World"
print(s.lower())
print(s.upper())
#将字符串转换成大小写
4.
s = "hello,world!"
print(s.split(","))
#根据标点符号对字符串进行分行
6.
s = input("书名:")
print(len(s))
#随意输入心中想到的一个书名,然后输出它的字符串长度(len属性)
7
s = input("s:")
print(s[::-1])
#接收用户输入的字符串,将其中的字符进行排序,并且以逆序输出
8
s = input("输入一句英文:")
b = s.split(" ")
print(b[::-1])
#用户输入一句英文,将其中的单词以反序输出
# 9.
s = input("输入一句话:")
print(s.find("呵"))
用户输入一句话,找出所有”呵“的位置
10.
s1 = ""
s = "War and heping》","《Notre Dame Cathedral》","《水浒传》","《三国演义》","《飘》","《红与黑》","《呼啸山庄》","《大卫·科波菲尔》","《悲惨世界》","《安娜·卡列尼娜》"
for i in range(1,len(s)+1):
for j in range(0,len(s[i])+1):
if j >10:
s[i] = s[7]
s1 += s[i]
else:
s1 += s[i]
print(s1)
11
s = input("输入一句话:")
print(s.find("呵呵"))
#用户输入一句话,找出所有”呵呵“的位置
12.
s1 = "abc","eae","DD"
s = "abc","eae","DD","asd","sadsad"
for i in range(0,len(s1)):
for j in range(0,len(s)+1):
if s1[i] == s[j]:
print("是")
break
#如何判断一个字符串是否是另一个字符串的子串
13. #如何验证一个字符串中的每一个字符均在另一个字符串中出现(不会)
ls = "sfd"
ls1 = "sfds"
ls = list(ls)
print(ls)
ls1 = list(ls1)
print(ls1)
if ls in ls1:
print("有子串的关系")
else:
print("没有任何关系")
14
import random
for i in range(0, random.randint(1,10)):
print(random.(string.ascii_letters) ,end="")
16
ls = "jian222"
if ls.isalnum():
print("既有数字又有字母")