How does None work? (In depth please) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

17th Jun 2019, 6:05 PM
Peter Conyer-Bowden
Peter Conyer-Bowden - avatar
3 Answers
+ 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
17th Jun 2019, 6:15 PM
Anna
Anna - avatar
+ 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 👍
17th Jun 2019, 6:18 PM
Peter Conyer-Bowden
Peter Conyer-Bowden - avatar
+ 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 👌
17th Jun 2019, 6:42 PM
Anna
Anna - avatar