Answer the question
In order to leave comments, you need to log in
How to concatenate in a for loop in PYTHON?
I concatenate in a loop
print(add_url) # oborydovanie/
for i in range(1 , 10):
add_pages.append('http://site.com/' + add_url + '?=' + str(i))
for a_pag in add_pages:
print(a_pag)
http://site.com/?=1
http://site.com/?=2
http://site.com/oborydovanie/?=1
, that is, the add_url variable loses its value. Why is this happening?
Answer the question
In order to leave comments, you need to log in
1. Format the code with the programming language.
2. Carefully work with indents, otherwise you will confuse yourself and everyone around and will not work correctly.
3. Provide the full code so you don't have to guess what's outside of your scraps. Where is add_url assigned? Maybe there has always been empty in general and does not lose anything.
4. Read, damn it, carefully your question after writing! Are you too lazy to read? Here we are not too lazy to answer, but are you too lazy to read? What a brazen disrespect for the community? What is "add_ur"? Where is it in your code, damn it ?!
5. Use format strings to pattern things like this. They are harder to make mistakes and screw up.
I summarize. You extremely inattentively pulled lines from the code, inserted it haphazardly, missed something, broke the indents, didn’t see something, and now you want us to brew coffee thicker and wonder what you have overlooked outside of your examples.
Replace
with
for the third python or for the second:
'http://site.com/' + add_url + '?=' + str(i)
f'http://site.com/{add_url}?={i}'
'http://site.com/{add_url}?={i}'.format(i=i, add_url=add_url)
nothing is lost
add_url ='oborydovanie/'
add_pages = []
for i in range(1 , 10):
add_pages.append('http://site.com/' + add_url + '?=' + str(i))
for a_pag in add_pages:
print(a_pag)
# Output:
# http://site.com/oborydovanie/?=1
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question