f-strings, short for formatted strings, allow us to display expressions like adding a string to a number, without any error.
print(f"{2} new messages")
Every f-string statement consists of two parts, first the character f
, then the string that we want to format.
print(f"{6} new messages")
Next, we add the different kind of value in curly braces so it'll display as one print statement. Like here, with {2}
.
print(f"{2} new messages")
Inserting variables like new_messages
between the curly braces displays their value too.
new_messages = 2
print(f"{new_messages} new messages")