Store function result into variable

storks

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)
vmonteco

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

store the result of xpath into an variable to assist in future query

From Dev

Cut of word from a string and store result to variable

From Dev

How to store query result (a single document) into a variable?

From Dev

How to store in a variable an echo | cut result?

From Dev

Cannot store result into variable SQL

From Dev

Store column result in variable

From Dev

Is it okay to store the result of a JQuery selector in a variable?

From Dev

Grep a variable and store the result in a vector in R

From Dev

How can I store a result of a function in a variable in Python?

From Dev

Python - Store function in variable

From Dev

store result of select query into array variable

From Dev

Store function result to variable for later use in PHP?

From Dev

Laravel: Return a database query result using the MySQL SUM function and store it in a variable

From Dev

Store the result of a command in a variable

From Dev

Store the assert failure result in a variable

From Dev

Store the result of a Dynamic Query in a variable

From Dev

store into variable a sudo result

From Dev

Assign the result of a function to variable?

From Dev

Store into variable result of function VBA

From Dev

Why store the result of getElementById() to a variable instead of using the function everytime?

From Dev

Store cmd Find result to a variable

From Dev

Store function result into variable

From Dev

How can I store a result of a function in a variable in Python?

From Dev

Sed Fails to store the result into a variable

From Dev

Store Result of SVN Command in Variable

From Dev

How can I store the result of a function into a variable?

From Dev

Store result of a query inside a function

From Dev

PHP: Store Result of JavaScript Function into a PHP Variable

From Dev

How to store a query result in a variable

Related Related

  1. 1

    store the result of xpath into an variable to assist in future query

  2. 2

    Cut of word from a string and store result to variable

  3. 3

    How to store query result (a single document) into a variable?

  4. 4

    How to store in a variable an echo | cut result?

  5. 5

    Cannot store result into variable SQL

  6. 6

    Store column result in variable

  7. 7

    Is it okay to store the result of a JQuery selector in a variable?

  8. 8

    Grep a variable and store the result in a vector in R

  9. 9

    How can I store a result of a function in a variable in Python?

  10. 10

    Python - Store function in variable

  11. 11

    store result of select query into array variable

  12. 12

    Store function result to variable for later use in PHP?

  13. 13

    Laravel: Return a database query result using the MySQL SUM function and store it in a variable

  14. 14

    Store the result of a command in a variable

  15. 15

    Store the assert failure result in a variable

  16. 16

    Store the result of a Dynamic Query in a variable

  17. 17

    store into variable a sudo result

  18. 18

    Assign the result of a function to variable?

  19. 19

    Store into variable result of function VBA

  20. 20

    Why store the result of getElementById() to a variable instead of using the function everytime?

  21. 21

    Store cmd Find result to a variable

  22. 22

    Store function result into variable

  23. 23

    How can I store a result of a function in a variable in Python?

  24. 24

    Sed Fails to store the result into a variable

  25. 25

    Store Result of SVN Command in Variable

  26. 26

    How can I store the result of a function into a variable?

  27. 27

    Store result of a query inside a function

  28. 28

    PHP: Store Result of JavaScript Function into a PHP Variable

  29. 29

    How to store a query result in a variable

HotTag

Archive