About Building Query Strings

You can build up a URL query string using the urlencode function:

1
2
3
4
5
6
7
8
9
>>> from urllib.parse import urlencode
>>> params = [
...     ("categories", 1),
...     ("categories", 2),
...     ("categories", 3),
...     ("page", 2),
... ]
>>> urlencode(params)
'categories=1&categories=2&categories=3&page=2'

Tips and Tricks Programming Python 3