+ 2
How does None work? (In depth please)
I am currently trying to wrap my head around the None expression, and am losing my mind over it. Sometimes it calls (None), other times it doesn't. Here is my code below. Please describe the differences between 'some_func' and print(var). https://code.sololearn.com/ckdu7Tf6TM7W/?ref=app
3 Réponses
+ 5
With var = some_func(), you save a call of the function some_func in the variable var. some_func() doesn't return anything, it just prints 'Hi!'. So when you print(var), you first call some_func(), which prints 'Hi!', and then print the return value of the function, which is None. Every function that doesn't explicitly return anything, implicitly returns None.
Try
var = some_func
without (), then you can call the function like this: var()
Or you could make some_func return the string 'Hi!' instead of printing it. Then print(var) would work
+ 4
Anna, this explains it in a much better and simplified manner than the course in python. Maybe you guys should edit this into the course? It doesn't explain it as well as you just did and would probably be easier for others as well. Thanks again for helping me out 👍
+ 3
Thank you for your kind words 😊
We can't edit the tutorials, but maybe a mail to info@sololearn.com helps. They're usually open to all kinds of suggestions 👌