I’m new to python, and I just want to know the difference between those examples.
Does it differ when it comes to the execution speed?
When do I use one of them instead of the other?
x: int = 64
print(f"Your Number is {x}")
and
x: int = 64
txt = "Your Number is {}"
print(txt.format(x))
Thank you in advance!
>Solution :
Python f-strings were added in 3.6. Therefore you should consider using format() if you need compatibility with earlier versions. Otherwise, use f-strings.
On macOS 12.1 running 3 GHz 10-Core Intel Xeon W and Python 3.10.2, f-strings are significantly faster (~60%)