today i learned:
Don’t use format or ‘+’
# ANNOYING
name = 'tom'
age = 5
s = 'my name is ' + name + ' and my age is ' + str(age)
# using f-strings
name = 'tom'
age = 5
s = f'my name is {name} and my age is {age}'
Why?
name = 'tom'
age = 5
height = 1.44
s = f'{name=} {age=} {height=}'
# name='tom' age=5 height=1.44
pi = 3.14159265
s = f'pi is {pi:.2f}'
# pi is 3.14