Search code examples
pythonfor-loopvariablescycle

Can I change a variable with the "X" of the cycle for?


I want to make a cycle for that changes part of the variable called "url". I have tried this but doest work, any suggestion?

for x in range(1, 10):

url == 'www.mywebsite_begining_of_link/',x,'/year_end_of_link'
print (url)

Thanks a lot!

I want this output:

www.mywebsite_begining_of_link/2/year_end_of_link
www.mywebsite_begining_of_link/3/year_end_of_link
     ...
     ...
www.mywebsite_begining_of_link/10/year_end_of_link```



Solution

  • You can try F-strings

    url = f'www.mywebsite_begining_of_link/{x}/year_end_of_link'
    print (url)