gpt4 book ai didi

python - 为什么 splat 运算符 (*) 仅用于方法参数?

转载 作者:行者123 更新时间:2023-11-28 22:28:02 26 4
gpt4 key购买 nike

<分区>

在 python 中,我可以使用 splat 运算符解压列表并将列表项作为参数发送给函数

dirs = ['this','is','a','file','path']
path = os.path.join(*dirs)
# path is now 'this/is/a/file/path'

我的问题是,为什么此功能仅限于方法参数?

例如,以下是无效语法:

x = [1,2,3]
y = [0,*x,4,5]

为什么这不会导致 [0,1,2,3,4,5]

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com