用format()函数
name = "wz" age = "25" with open("C:/Users/{0}_{1}.txt".format(name, age), "w", encoding = "utf-8") as f1: f1.write("hellow world")
则文件名为 wz_25.txt