diff --git a/guide/english/python/python-f-strings/index.md b/guide/english/python/python-f-strings/index.md index f6ecfed1fc..69449fb60c 100644 --- a/guide/english/python/python-f-strings/index.md +++ b/guide/english/python/python-f-strings/index.md @@ -75,6 +75,7 @@ print(func) ``` The sum of 3 + 5 is 8 ``` + ### Joining the contents of a collection within a string: #### Input @@ -90,9 +91,10 @@ print(list_str) ``` List of fruits: Apple, Banana, Pear ``` + ### Convert an integer to 8-bit binary -### Input +#### Input ```python num = 42 @@ -100,10 +102,34 @@ num = 42 print(f'The binary of {num} is {num:08b}') ``` -### Output +#### Output ``` The binary of 42 is 00101010 ``` +### Using Object with f-strings + +#### Input + +```python +class Book: + def __init__(self, title, author): + self.title = title + self.author = author + + def __str__(self): + return f"{self.title} by {self.author}" + + +book = Book("A Clash of Kings", "George R. R. Martin") + +print(f"{book}") +``` + +##### Output +``` +A Clash of Kings by George R. R. Martin +``` + ### Sources https://www.python.org/dev/peps/pep-0498/