Snippets tagged “str”
3 snippets use this tag.
- How to get a function name as a string?Python
In Python, you can use the built-in function attribute __name__ to get the name of a function as a string.
- How to print instances of a class using print()?Python
To print instances of a class using the built-in print() function, you can define a __str__ method within the class.
- What is the difference between __str__ and __repr__?Python
__str__ and __repr__ are two special methods in Python classes.