本文介绍了如何忽略函数返回的其余参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
def get():
...
...
return x,y,z
a,b,c = get()
我不需要 b,c 有没有办法忽略它们(像不在乎的东西)
i don't need b, c is there a solution to ignore them (something like don't care)
推荐答案
推荐的做法是使用 _ 变量名,正如 Abdul Niyas PM 所指出的,这不会存储 _ 捕获的值.
The recommended way of doing this is to use the _ variable name, as indicated by Abdul Niyas P M, this will not store the values captured by the _.
x, _, z = 1, 2, 3 # if x and z are necessary
# or
x, *_ = 1, 2, 3 # if only x is necessary
这篇关于如何忽略函数返回的其余参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!