我有一个变量,其值在“某些函数”中增加一个,我想将其最后一个值传递给“另一个函数”!知道此变量位于“某些功能”和“某些功能”中间 这两个功能属于同一类 我希望你对我很了解:) 这是我的代码
class myClass:
counter = 0
def someFunction():
#here is some codes
string = "my string"
globale counter
for i in range(0, len(string))
counter += 1
return string
def anotherFunction():
return counter
答案 0 :(得分:0)
有几种方法可以解决此问题:
Multiple managers are loaded of type: InputManager
Multiple managers are loaded of type: GraphicsSettings
Multiple managers are loaded of type: PhysicsManager
Multiple managers are loaded of type: QualitySettings
Multiple managers are loaded of type: Physics2DSettings
Multiple managers are loaded of type: VFXManager
中将其退回:someFunction()
class myClass:
counter = 0
def someFunction(self, counter):
#here is some codes
string = "my string"
for i in range(0, len(string))
counter += 1
return string, counter
def anotherFunction(self):
return someFunction()[1]
class myClass:
def __init__(self):
self.counter = 0
def someFunction(self):
#here is some codes
string = "my string"
for i in range(0, len(string))
self.counter += 1
return string
def anotherFunction(self):
return self.counter
关键字创建一个全局变量。不要这样做。