Jul-09-2019, 08:10 PM
Now that looked at
f-string are far more readable and concise,less prone to error than other ways of formatting,they are also faster!
format()
forget it,in my option learn and only use f-string
.f-string are far more readable and concise,less prone to error than other ways of formatting,they are also faster!
>>> first_name = 'Eric' >>> last_name = 'Idle' >>> print(f'Welcome {first_name} {last_name} to Python forum') Welcome Eric Idle to Python forum >>> name = 'f-string' >>> print(f"String formatting is called {name.upper():*^20}") String formatting is called ******F-STRING****** # f-strings can take any Python expressions inside the curly braces. >>> cost = 99.75999 >>> finance = 50000 >>> print(f'Toltal cost {cost + finance:.2f}') Toltal cost 50099.76 >>> for word in 'f-strings are cool'.split(): ... print(f'{word.upper():~^20}') ... ~~~~~F-STRINGS~~~~~~ ~~~~~~~~ARE~~~~~~~~~ ~~~~~~~~COOL~~~~~~~~