+ 1

Why does the console returns None in the program below:

Hi i have started learning python3 with sololearn. Im having difficulties in some area. def my_func(): print('Hi!') Var = my_func() print(var) I dont understand why this program returns none along with Hi! as output. Can anybody put some light on this?

17th Nov 2018, 6:09 PM
Risav Ghosh
Risav Ghosh - avatar
1 Resposta
+ 2
The function my_func doesn't return anything, so var gets set to None. If you want it to become something different, you can add a return statement to the end of the function. For example: def my_func(): return "Hi!" var = my_func() print(var) This will print Hi!, and nothing else.
17th Nov 2018, 6:33 PM
Cailyn Baksh