jskfan
asked on
Understanding Python Functions
Understanding Python Functions
I have this Python code :
I would like to know the meaning of Self in : the function Roll. is it a parameter that needs an argument passed to it ? if so what argument was it passed to it in the above example?
I also want to understand the Return keyword. in the example above the result from variables first and second will be returned but where does it get stored ?
it should be store in the function Roll, but where ? in the Self parameter ?
Any clarification will be very much appreciated.
Thank you
I have this Python code :
import random
class Dice:
def Roll(self):
first=random.randint(1,6)
second=random.randint(1,6)
return first,second
dice=Dice()
print(dice.Roll())
I would like to know the meaning of Self in : the function Roll. is it a parameter that needs an argument passed to it ? if so what argument was it passed to it in the above example?
I also want to understand the Return keyword. in the example above the result from variables first and second will be returned but where does it get stored ?
it should be store in the function Roll, but where ? in the Self parameter ?
Any clarification will be very much appreciated.
Thank you
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You don't really need a class for this. Your Roll function can stand on its on without the need for a class.
ASKER
Thank you