Marks Notes

f-strings

f-strings in python allow you to insert variables into a string. To use an f-string, place the f character in front of the string, and the variable in curly braces {}

Examples

Basic usage

myvar = 4
print(f"I want to print the number {4}")

With logic

n1 = 4
n2 = 3
print(f"{n1 + n2} is the sum of {n1} and {n2}")

If you need to escape the curly braces

print(f"The value is {{{value}}}")