a=('李晨','劉勇','趙雪','王峰')
b=(89,92,76,65)for i inrange(0,4):print(f"{a[i]}的成績為:{b[i]}")//方法1print("%s的成績為:%d"%(a[i],b[i]))//方法2//方法3print("%s的成績為:%d"%(a[0],b[0]),"%s的成績為:%d"%(a[1],b[1]),"%s的成績為:%d"%(a[2],b[2]),"%s的成績為:%d"%(a[3],b[3]),sep='\n')
import re
s="NevergIveup!"
new_s= re.sub(r'I','i',s)print(new_s)
將“Today is a nice day.”這句英語文本中的單詞進行倒置,標點不倒置。 經過倒置后變為:“Day nice a is today.”
import re
s ="Today is a nice day."print(" ".join(reversed(s.rstrip(".").split())).lower().capitalize()+".")
輸出下面這段英文中所有長度為4個字母的英文單詞。
import re
x ="Never give up,Never lose hope.Always have faith,It allows you to cope."
re_str =r'[a-zA-Z]{4}'print(re.findall(re_str,x))//方法1pattern = re.compile(r"[a-zA-Z]{4}")print(pattern.findall(x))//方法2