The class in python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

The class in python

Hi. Why the method describe_restaurant returns me None? How can I avoid it? https://code.sololearn.com/cypNXIPW7r0N/?ref=app

6th Apr 2020, 1:13 PM
Katja
Katja - avatar
3 Answers
+ 4
If you want to get a value returned by a function / method (appart some special cases such as __new__ and __init__ magic methods), you must return it explicitly. What you're doing actually, is to print inside the method AND print the value returned by the method (None). The more logical fix, would be to replace your print inside the method by returning the value: def describe_restaurant(self): return 'Its ' + self.restaurant_name + ' and you can order ' + self.cuisine_type +'.' ... same logic for the open_restaurant methid ;)
6th Apr 2020, 1:19 PM
visph
visph - avatar
+ 2
You just need to call the function. restaurant.describe_restaurant() Because this function prints something out. Don't call this function in print function.
6th Apr 2020, 1:18 PM
Mustafa K.
Mustafa K. - avatar
0
Anish Gurjar Stop spamming the Q&A section with code adversiting (you're posted a bunch since few minutes)
6th Apr 2020, 2:20 PM
visph
visph - avatar