Link to home
Start Free TrialLog in
Avatar of jskfan
jskfanFlag for Cyprus

asked on

Understanding Python Functions

Understanding Python Functions

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

Open in new window


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
Avatar of pepr
pepr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You don't really need a class for this.  Your Roll function can stand on its on without the need for a class.
Avatar of jskfan

ASKER

Thank you