import re
text ="""I am xiao xiao. I have over 8 years of experience in marketing. I am the
team manager of marketing for HP since 2013"""#1.把以上字符串的所有空格删掉,并保存在另外一个新的字符串中。
a = text.replace(" ","")print(a)print("空格"," "*len(re.compile(" ").findall(text)))#2. 判断以上单词的个数。print("个数",len(text.split(" "))-len(re.compile(r'\d+').findall(text)))#3.把以上所有包含了 t(不区分大小写)的单词都找出来。# print(re.findall('t+',text.lower(),flags=re.IGNORECASE))list= text.lower().split(" ")for i inlist:if i.find("t")!=-1:print(i,end=" ")print(3)#4.把以上所有的数字都找出来。print(re.compile(r'\d+').findall(text))
一 按要求格式化字符串import retext = """I am xiao xiao. I have over 8 years of experience in marketing. I am the team manager of marketing for HP since 2013"""#1.把以上字符串的所有空格删掉,并保存在另外一个新的字符串中。a = text.replace(" ","")print(a)print("空格"," "*len(re.compile(" ").f