This question already has an answer here:
- What is the purpose of the return statement? 12 answers
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.
Generally, you
return
the value. Once you've done that, you can assign a name to the return value just like anything else: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 ...
You can simply store the value of random.random() as you are doing to store in a, and after that you may return the value
You can make it a global variable if you don't want to return it. Try something like this