def function1(word,number):
print word
print number
def function2():
print word*2
print number*2
function1('Word',0)
function2() ##How do I make a call to function2 that automatically uses the previous variables word and number?
Python function inheritance?
I'm not sure if the title is 100% accurate but I'll try to describe what I'm having troubles with as well as I can. I want a second function to be able to recognize the variables defined in function1...here's some code to help show what I mean. I think what I'm looking for is called inheritance but using google I wasn't able to word properly what I was searching for.
I'm not sure if the title is 100% accurate but I'll try to describe what I'm having troubles with as well as I can. I want a second function to be able to recognize the variables defined in function1...here's some code to help show what I mean. I think what I'm looking for is called inheritance but using google I wasn't able to word properly what I was searching for.
def function1(word,number):
print word
print number
def function2():
print word*2
print number*2
function1('Word',0)
function2() ##How do I make a call to function2 that automatically uses the previous variables word and number?
class MyType:
def func1(self, word, number):
self.word = word
self.number = number
def func2(self):
print self.word
print self.number
In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement