Use the format () method.
id_user = 1
url = 'https://api.stackexchange.com/2.2/users/{0}?order=desc&sort=reputation&site=stackoverflow'
request = urllib2.Request(url.format(id_user))
You can use%, like this:
url = "...users/%s?order..." % id_user
It will work, but always prefer the format () method. As described by the official documentation , it handles common concatenation errors, and will be the official method used by Python from now on. The idea is that soon the% is no longer accepted.
You can also use "plus operation":
url = '...user/' + id_user + '?order...'
But it's a bad practice. When the code becomes larger (and you should always think about it), this url will be unreadable. If you need to join two strings quickly, you may want to use join ().
url = ''.join(['...user/',
id_user,
'?order...'])
In summary, use format () . That's what Python asks you to use, after all.