ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
``` import keyword import re url = "www.baidu.com" # 匹配包含www的字符串 re_compile = re.compile("www") # match从起始位置开始匹配,且只匹配一次,如果不没找到,则返回None match = re_compile.match(url) # .span用来获取匹配到的字符串所对应的下标位置 #re_compile.match(url).span() # match返回的是match对象,获取值使用group print(match.group()) import re line = "Cats are smarter than dogs" # .* 表示任意匹配除换行符(\n、\r)之外的任何单个或多个字符 matchObj = re.match(r'(.*) are (.*) .*', line, re.M | re.I) if matchObj: print("matchObj.group() : ", matchObj.group()) print("matchObj.group(1) : ", matchObj.group(1)) print("matchObj.group(2) : ", matchObj.group(2)) else: print("No match!!") class switch_case(object): def case_to_function(self, case): fun_name = "case_fun_" + str(case) method = getattr(self, fun_name, self.case_fun_other) return method def case_fun_1(self, msg): print(msg) def case_fun_2(self, msg): print(msg) def case_fun_other(self, msg): print(msg) ``` ``` import keyword table = ["def","set","len","input","print"] new ="" temp ="" file = open("6183.py","r",encoding="utf-8") conent = file.read() #print(conent) file.close() for ch in conent: if ch.isalpha(): #i1 = i.upper() temp += ch #print(temp) else: print(temp) if(not keyword.iskeyword(temp)) and (temp not in table): temp = temp.upper() new += temp new += ch temp = '' #temp += i #print(new) newfile = open("6184.py","w",encoding="utf-8") newfile.write(new) newfile.close() ``` ``` def judge(n): m =set(n) if len(m) != len(n): return True else: return False line = input("请输入一串列表值:") print(judge(line)) ``` ``` def JUDGE(N): M =set(N) if len(M) != len(N): return True else: return False LINE = input("请输入一串列表值:") print(JUDGE(LINE)) ``` ``` def JUDGE(N): M =set(N) if len(M) != len(N): return True else: return False LINE = input("请输入一串列表值:") print(JUDGE(LINE)) ``` ``` import keyword temp = 'return' a = not keyword.iskeyword(temp) #print(a) b = ['set'] c = temp not in b #print(c) print(temp.upper()) ```