Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

Say I have a Python function that returns multiple values in a tuple:

def func():

   return 1, 2

Is there a nice way to ignore one of the results rather than just assigning to a temporary variable? Say if I was only interested in the first value, is there a better way than this:

x, temp = func()

1 Answer

0 votes
by (106k points)

To Ignore python multiple return value you can use the  "_" as a variable name for the elements of the tuple.

You can see the below-mentioned code for the same:-

def f():

return 5, 4, 9

_, _, a = f()

image

Related questions

0 votes
4 answers
0 votes
1 answer
asked Oct 10, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
0 votes
1 answer
asked Jul 17, 2019 in Python by Sammy (47.6k points)

1.2k questions

2.7k answers

501 comments

693 users

Browse Categories

...