且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在同一行中打印2个for循环的结果

更新时间:2023-08-28 14:47:10

您也许可以压缩两个结果:

You could maybe zip the two results:

names = soup.find_all('h2')
rest = soup.find_all('span', {'class' : 'amount'})
for div, a in zip(names, rest):
    print('{} - {}'.format(div.text, a.text))
    # print(f"{div.text} - {a.text}")   # for python > 3.6