Code Yarns ‍👨‍💻
Tech BlogPersonal Blog

Python: Printing a class/object

📅 2009-Oct-08 ⬩ ✍️ Ashwin Nanjappa ⬩ 🏷️ classes, objects, python, strings ⬩ 📚 Archive

class Foobar:

    def __init__(self, val0, val1):
        self.val0 = val0
        self.val1 = val1

    def __repr__(self):
        """String representation of class/object."""
        return "{} and {}".format(self.val0, self.val1)

fbar = Foobar(99, 100)
print(fbar) # 99 and 100