如何遍历f字符串中的多个变量

时间:2019-11-17 04:58:29

标签: python loops

基本上,我需要为每个字母100x打印以下内容

print(f"https://www.gurufocus.com/stock_list.php?m_country[]=USA&a={letter}&p={i}&n=30")

我能够遍历数字并将其打印100x,但是不确定如何移动到下一个字母,直到到达字母Z。我们将不胜感激。

我希望每个字母运行100x。

任何帮助将不胜感激。

number = 0
letter = 'A'
while number  < 100:
    print(f"https://www.gurufocus.com/stock_list.php?m_country[]=USA&a={letter}&p={i}&n=30")
    letter = bytes(letter, 'utf-8')
    letter = str(bytes(letter[0] + 1)).upper()
    number  += 1

1 个答案:

答案 0 :(得分:0)

f字符串使用

import string

for letter in string.ascii_uppercase: # you can change if you need lower, string.ascii_lowercase
    for i in range(100):
        url = f"https://www.gurufocus.com/stock_list.php?m_country[]=USA&a={letter}&p={i}&n=30"
        print(url)

过去的答案

import string

url_form = "https://www.gurufocus.com/stock_list.php?m_country[]=USA&a={letter}&p={i}&n=30"
for letter in string.ascii_uppercase: # you can change if you need lower, string.ascii_lowercase
    for i in range(100):
        url = url_form.format(letter=letter, i=i)
        print(url)
'''