I am trying to save the result of a function into a variable and print that variable on the screen, but when I print I see "none".
How to repair this?
import time;
def hours():
localtime = time.localtime(time.time())
print (localtime.tm_hour)
def minutes():
localtime = time.localtime(time.time())
print (localtime.tm_min)
def seconds():
localtime = time.localtime(time.time())
print (localtime.tm_sec)
hours()
minutes()
seconds()
var = hours()
print(var)
You need to return a value that will be stored into the variable.
This way :
def myfunction():
value = "myvalue"
return value
var = myfunction()
print(var)
>>> "myvalue"
Currently you're just printing the value in your function, not returning it , that's two different things.
Edit: Also note that the default returned value is None
when there is no return directive.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments