Search code examples
pythontuplesreturn-value

How to ignore the rest of the parameters that return by the function?


def get():
   ...
   ...
   return x,y,z

a,b,c = get()

i don't need b, c is there a solution to ignore them (something like don't care)


Solution

  • 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