How to add parameters to url in python

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.

>Solution :

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}'

Leave a Reply