Concate str with int using f

Posted under » Python on 08 June 2022

A simple string concatenate in Python.

goyayfeels = '/feels/'+ str(goyay) +'/' 

However, if you try to concatenate string and int using + operator, you will get a runtime error.

One way to get around this is by using the format() function

 call = requests.get(f'http://api.com/sid/A{user_id + 3}-2')

In Python, string and numbers don't mix, so this will work

salty = str(entry['uid']) 
call = requests.get(f'http://api.com/sid/{salty}')

Where user_id is an integer. However, this only works in Python 3.6 and above.

web security linux ubuntu python django git Raspberry apache mysql php drupal cake javascript css AWS IOT