Only magic methods can return any value, is it so? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Only magic methods can return any value, is it so?

What I am seeing till now is that only magic methods are returning values, which other methods are just editing those. Somebody clarify pls..

25th Feb 2019, 12:59 PM
Govind Kumar Arora
Govind Kumar Arora - avatar
1 Answer
+ 2
All kinds of functions, be they free or part of a class (aka methods), can return or not return values! It depends on if there's a return statement or not: def f(): print('Hello') returns nothing. def f(): print('Hello') return 1 returns 1. (__init__ is a 'magic method' and is not allowed to have a return value - so you see it has nothing to do with mm or not mm.)
25th Feb 2019, 1:26 PM
HonFu
HonFu - avatar