我想在url里面插入一个数字循环,1-9数字之前需要加一个0,怎么实现
for i in range(1, 12):if i<10:
i = f"0"+i
url = f"http://lishi.tianqi.com/beijing/2018{i}.html"
如果年份2018哪里也想该改成循环,需要怎么改,用同样的逻辑吗?
本帖最后由 suchocolate 于 2021-11-29 22:46 编辑
for j in range(1970, 2022):
for i in range(1, 13):
url = f"http://lishi.tianqi.com/beijing/{j}{i:0>2d}.html"
print(url)
字符串格式化:https://www.runoob.com/python/att-string-format.html suchocolate 发表于 2021-11-29 22:44
字符串格式化:https://www.runoob.com/python/att-string-format.html
{:5_108:}谢谢!!
页:
[1]