假设我有很多变量,而不是每次都在内部写(),是否有更简单的方法将所有变量压缩成一个单词?
def numbers():
a = 1
b = 2
c = 3
d = 4
e = 5
f = 6
g = 7
h = 8
i = 9
new_variable(a, b, c, d, e, f, g, h, i)
def new_variable(a, b, c, d, e, f, g, h, i):
j = g + i
print (j)
new_variable_2(a, b, c, d, e, f, g, h, i)
def new_variable_2(a, b, c, d, e, f, g, h, i):
k = g + h
print (k)
new_variable_3(a, b, c, d, e, f, g, h, i)
def new_variable_3(a, b, c, d, e, f, g, h, i):
l = h + i
print (i)
numbers()
答案 0 :(得分:1)
你可以这样试试:
a, b, c, d, e, f, g, h, i = range(1,10)
alphabet = [a, b, c, d, e, f, g, h, i]
def new_variable(*alphabet):
j = g + i
print (j)
new_variable_2(*alphabet)
def new_variable_2(*alphabet):
k = g + h
print (k)
new_variable_3(*alphabet)
def new_variable_3(*alphabet):
l = h + i
print (i)
new_variable(*alphabet)
返回与您的代码相同的数字。