May 2018
Beginner to intermediate
282 pages
7h 58m
English
In Python 3, you might see string literals prefixed by an f. These strings may contain expressions inside curly brackets, similar to the format strings accepted by str.format(). They will be evaluated at runtime using the format() protocol.
Here are some examples:
>>> class Person:
... def __init__(self, name):
... self.name = name
... def __str__(self):
... return f"name is {self.name}"
...
>>> p = Person("Hexa")
>>> str(p)
'name is Hexa'
Though this syntax might seem alien at first, you will find it to be more convenient to use than the alternatives for string formatting.
Read now
Unlock full access