PEP 498 introduces a new kind of string literals: f-strings, or formatted string literals.
Formatted string literals are prefixed with 'f'
and are similar to the format strings accepted by str.format()
. They contain replacement fields surrounded by curly braces. The replacement fields are expressions, which are evaluated at run time, and then formatted using the format()
protocol
Example: >>> name = "Fred" >>> f"He said his name is {name}." 'He said his name is Fred.' Example: val1 = 'tutorials' val2 = 'learning' print(f"{val1}for is a website for {val2}.") output : tutorialsfor is a website for learning. Example: name = 'Saif' age = 30 print(f"Hello, My name is {name} and I'm {age} years old.") output : Hello, My name is saif and I'm 30 years old.