Created
July 29, 2022 16:12
-
-
Save ustropo/168555a15a10594632ad8e4f50b364fb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyClass: | |
def __repr__(self) -> str: | |
return 'My Class Repr' | |
def __str__(self) -> str: | |
return 'My Super Class' | |
def __format__(self, __format_spec: str) -> str: | |
return 'My Formatted Class' | |
mc = MyClass() | |
print(f"Usual format call: {mc}") | |
## 'Usual format call: My Formatted Class' | |
print(f"Force str: {mc!s}") | |
## 'Force str: My Super Class' | |
print(f"Force repr: {mc!r}") | |
## 'Force repr: My Class Repr' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment