如果我们将变量(x,y)传递给函数并且不传递它,为什么下面的两个代码都会给出相同的结果
def gen():
yield (x + y)
yield (x - y)
x = int(input("X = "))
y = int(input("Y = "))
g = gen()
while True:
try:
print(next(g))
except:
print("END!")
break
def gen(x,y):
yield (x + y)
yield (x - y)
x = int(input("X = "))
y = int(input("Y = "))
g = gen(x,y)
while True:
try:
print(next(g))
except:
print("END!")
break