+ 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
3 ответов
+ 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 ;)
+ 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.
0
Anish Gurjar
Stop spamming the Q&A section with code adversiting (you're posted a bunch since few minutes)