如何忽略函数返回的其余参数? [英] How to ignore the rest of the parameters that return by the function?

查看:41
本文介绍了如何忽略函数返回的其余参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

这篇关于如何忽略函数返回的其余参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆