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

Shawdotion

I'm trying to store the result of random.random into a variable like so:

import  random

def randombb():
 a = random.random()
    print(a)

randombb()

How can I properly get a?

Thanks.

mgilson

Generally, you return the value. Once you've done that, you can assign a name to the return value just like anything else:

def randombb():
    return random.random()

a = randombb()

As a side note -- The python tutorial is really great for anyone looking to learn a thing or two about the basics of python. I'd highly recommend you check it out. Here is the section on functions: https://docs.python.org/2/tutorial/controlflow.html#defining-functions ...

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

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

From Dev

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

From Dev

how can i store the printing result, obtained by "for statement" variable?

From Dev

Store function result into variable

From Dev

Store function result into variable

From Dev

Python - How to store a Search Result (list) in a variable?

From Dev

How can I store the result of .each() into localStorage?

From Dev

Can I store the result of Fetch in a global variable using JavaScript?

From Dev

Store into variable result of function VBA

From Dev

Can I store slicers in a variable? (Pandas/Python)

From Dev

PHP - How can I store variable states?

From Dev

How can I store the output of summary in a variable?

From Dev

How can I store a knex query in a variable?

From Dev

How can I store dataset() in Application variable?

From Dev

How can I store my variable in a file?

From Dev

how can executorService store result of task `i` in `array[i]`?

From Dev

How do I store a mongodb query result in a variable?

From Dev

In python 3 how can I return a variable to a function properly?

From Dev

Python- How can I access a variable outside of a function?

From Dev

python: how can I pass a variable to a function with only the string name

From Dev

How can I always pass the current variable value into a python function?

From Dev

how I can call from batch file a java script function with 2 arguments and return the result to a dos variable

From Dev

Python - Store function in variable

From Dev

How to store a query result in a variable

From Dev

Python: Can I store a variable name within a variable?

From Dev

How can I store reference to the result of an operation in Go?

From Dev

How can i store the result of SRANDMEMBER with a COUNT argument in a SET?

From Dev

How can i store the result of SRANDMEMBER with a COUNT argument in a SET?

From Dev

How can I store the result of MongoDB query in a text file with Nodejs?

Related Related

  1. 1

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

  2. 2

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

  3. 3

    how can i store the printing result, obtained by "for statement" variable?

  4. 4

    Store function result into variable

  5. 5

    Store function result into variable

  6. 6

    Python - How to store a Search Result (list) in a variable?

  7. 7

    How can I store the result of .each() into localStorage?

  8. 8

    Can I store the result of Fetch in a global variable using JavaScript?

  9. 9

    Store into variable result of function VBA

  10. 10

    Can I store slicers in a variable? (Pandas/Python)

  11. 11

    PHP - How can I store variable states?

  12. 12

    How can I store the output of summary in a variable?

  13. 13

    How can I store a knex query in a variable?

  14. 14

    How can I store dataset() in Application variable?

  15. 15

    How can I store my variable in a file?

  16. 16

    how can executorService store result of task `i` in `array[i]`?

  17. 17

    How do I store a mongodb query result in a variable?

  18. 18

    In python 3 how can I return a variable to a function properly?

  19. 19

    Python- How can I access a variable outside of a function?

  20. 20

    python: how can I pass a variable to a function with only the string name

  21. 21

    How can I always pass the current variable value into a python function?

  22. 22

    how I can call from batch file a java script function with 2 arguments and return the result to a dos variable

  23. 23

    Python - Store function in variable

  24. 24

    How to store a query result in a variable

  25. 25

    Python: Can I store a variable name within a variable?

  26. 26

    How can I store reference to the result of an operation in Go?

  27. 27

    How can i store the result of SRANDMEMBER with a COUNT argument in a SET?

  28. 28

    How can i store the result of SRANDMEMBER with a COUNT argument in a SET?

  29. 29

    How can I store the result of MongoDB query in a text file with Nodejs?

HotTag

Archive