jcm*_*ald 1 python variables arguments function
我只是将论据从一个def语句传递到def另一个语句。我不知道您可以传递的参数数量没有限制。我假设参数是变量。我需要能够传递超过255个参数。有人可以用外行术语帮助我如何解决“超过255个参数”。谢谢!
码:
def a():
"Things happening"
variable1
b(variable1)
def b(variable1):
"Things happening"
variable2
c(variable1, variable2)
def c(variable1, variable2):
"Things happening"
variable3
d(variable1, variable2, variable3)
.
.
.
def z5(variable1,...variable256):
print result
main()
Run Code Online (Sandbox Code Playgroud)
小智 6
在python 3.7中,您现在可以传递超过255个参数。
看这里:
https://docs.python.org/3.7/whatsnew/3.7.html
https://bugs.python.org/issue12844
https://bugs.python.org/issue18896
小智 5
Python 有目的地阻止您传递超过 255 个参数,因为这样做的代码非常笨拙且难以维护。如果一个函数需要那么多参数(或任何接近该数量的参数),则意味着设计中存在缺陷。
如果您确实需要 +255 个不同的值,那么您应该将它们全部放在一个列表中,并使您的函数接受该值:
def z5(list_of_values):
...
z5([val1, val2, val3, ...])
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5322 次 |
| 最近记录: |