What is the usual/clearest way to write this in Python?
value, _ = func_returning_a_tuple()
or:
value = func_returning_a_tuple()[0]
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
value = func_returning_a_tuple()[0]seems clearer and also can be generalized.What if the function was returning a tuple with more than 2 values?
What if the program logic is interested in the 4th element of an umpteen tuple?
What if the size of the returned tuple varies?
None of these questions affects the subcript-based idiom, but do in the case of multi-assignement idiom.