How to add parameters to url in python

Question:

Hello i have this code in javascript i have made where i give parameters in the url this is the javascript code:

let user_id = '1234567890';

var chat_id = ['@test1','@test2'];

url: `https://api.telegram.org/bot1234567890/banChatMember?chat_id=${chat_id[i]}&user_id=${user_id}`

This code works great the paramets pass, my question is if it is possible to do something like this in python i saw some passing parameters but i couldnt understand it thats why im asking here.

Asked By: laraCoder

||

Answers:

You can use f-strings for this. (Note that regular string concatenation with + always works in these cases, as well.)

user_id = '1234567890'
chat_id = ['@test1','@test2']
i = 0
url = f'https://api.telegram.org/bot1234567890/banChatMember?chat_id={chat_id[i]}&user_id={user_id}'
Answered By: Unmitigated
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.