O
O
Omolix2020-09-12 11:53:33
Python
Omolix, 2020-09-12 11:53:33

What to do with TypeError: can only concatenate str (not "int") to str?

In short, I am mastering vk api for myself and decided to draw a conclusion from the data from the link. Link example vk.com/v=0 .
I have a link 'vk.com/' added with 'v=0' through '+' ('vk.com/' + v= + peremennaya)
below I have a loop that adds to v +1, it adds a number to vk. com/v=0 and performs an action on it.
But the loop does not work in Python, because I convert the number to a string so that I can connect it with a link, but because of this, the loop does not work (because it cannot add a number to the string).
Thank you all in advance, here is a sample code:

offset = 0
res = 'https://vk.com/v=' + 0

while (c != 10):
  offset += 1
  c += 1

(Error code: TypeError: can only concatenate str (not "int") to str)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
StarCatSTT, 2020-09-12
@StarCatSTT

'https://vk.com/v=' + 0

You add a string and a number
'https://vk.com/v=' + str(0)
while (c != 10):
  offset += 1
  c += 1

Why is while here?
It can be easier:
for c in range(10):
    offset += 1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question