f“字符串{变量}字符串”
例url=f"www.{b}.com"
import random
from urllib import request
import requests
a=1
f = open(r'D:\PY\url.txt','w')
while a<9:
b= random.randint(1,933)
url=f"www.{b}.com"
print(str(url),file=f)
a+=1
f.close()
输出
aaa1
url="%d.com"%aaa
输出
1.com