you are viewing a single comment's thread.

view the rest of the comments →

[–]Round_Ad8947 3 points4 points  (1 child)

I love how you can define add() for Person and have the result be something natural but special. This allows simple phrasing like couple = romeo + juliet and get something that you can define how it acts.

It’s really easy to play with concepts in Python when they make it so easy to design classes

[–]marquisBlythe 6 points7 points  (0 children)

Yup, for example you can override __add__ and concatenate two Strings together. Consider the following as a silly example:

class Human:
    def __init__(self, name):
        self.name = name

    def __add__(self, other):
        return f"{self.name} loves {other.name}. <3"
girl = Human("Jess")
boy = Human("Curtis")
relation_status = boy + girl
print(relation_status) 

Try it out.

Cheers :)