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

About None in Python

def some_func(): print("Hi!") var = some_func() print(var) My question is, why var does not return Hi! IF that already was defined when I write def some_func(): print("Hi!") Can someone clarify it to me? Thanks in advance :)

3rd Feb 2019, 4:12 PM
diegotco
4 Answers
+ 6
var doesn't return anything, var is the name you give for what the function returns. And a function only returns something if you specify that. If you don't, var will be None. So in the function you'd have to write: return 'Hi!' Then var would contain 'Hi!' and you could print it out as expected.
3rd Feb 2019, 4:25 PM
HonFu
HonFu - avatar
+ 5
None is correct as your function doesn't return anything.
3rd Feb 2019, 6:00 PM
Hubert Dudek
Hubert Dudek - avatar
+ 2
Var will return None
4th Mar 2019, 3:35 PM
Hacker
+ 1
Since the function itself prints "Hi!" just call the function normally: some_func() No need to save it to a variable (var in this case). Check the link below for a refresher on none (the answer is on the 2nd page of the link): https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2449/?ref=app Hint: Try to read the comments section of the lesson. You will find very useful info there.
3rd Feb 2019, 7:12 PM
Lambda_Driver
Lambda_Driver - avatar