def method(self, *args):
def function(*args):
#can this access all method's variables, data, etc.
def method(self, *args): def function(*args): #can this access all method’s variables, data, etc.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes you can,because python follows the following look-up rule while finding a variable:
LEGB:
So, in your case it’s
E:python 2.x:
in python 2.x you can’t modify those variables in the func
output:
python 3.x:
use
nonlocalto even modify the variables:output: