A
A
Anton2018-02-19 19:47:50
Python
Anton, 2018-02-19 19:47:50

Why None when calling the super().__add__() method?

There is a simple class

class C(int):
    def __add__(self, other):
        super(C, self).__add__(other)

a = C(1)
print(a+1)

I did not override the parent method, but instead of 2 I get -
None
Why?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stanislav Pugachev, 2018-02-19
@TonyTrueTony

if return is not specified in the function, then None is always returned by default

A
Anton, 2018-02-20
@TonyTrueTony

Thank you!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question