I use only f-string for string formatting now,and have done so for a while(years).
They are more readable,more concise,and less prone to error than other ways of formatting,they are also faster!.
For me is very simple to see this.
There is no need to measure,they are faster.
They are more readable,more concise,and less prone to error than other ways of formatting,they are also faster!.
For me is very simple to see this.
>>> name = "Kent" >>> age = 30 # The expressions is in the string where the belong >>> print(f"Hello, {name}. You are {age}.") Hello, Kent. You are 30. # The expressions is behind and not where the should be,and only {} in string >>> print("Hello, {}. You are {}.".format(name, age)) Hello, Kent. You are 30.
(Sep-16-2019, 06:31 AM)newbieAuggie2019 Wrote: 2) Is it something with f-strings and newlines to be timed? (no problems to print)Don't pack in a string,use a function.
There is no need to measure,they are faster.
import timeit def run_me(): newline = '\n' first = 'first' second = 'second' "\n\nThis is printing strings with f-formatting:" f'{first}{newline}{second}' #'{}{}{}'.format(first, newline, second) print(timeit.Timer("run_me()",'from __main__ import run_me').timeit(number=10000000))
Output:f-string: 3.2901052
.format(): 6.3253624