About None in Python | Sololearn: Learn to code for FREE!

+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 :)

2/3/2019 4:12:14 PM

diegotco

4 Answers

New Answer

+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.

+5

None is correct as your function doesn't return anything.

+2

Var will return None

+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/Python/2449/?ref=app Hint: Try to read the comments section of the lesson. You will find very useful info there.