Ignore Python Multiple Return Value

Blog-32.jpg

We can ignore one or more return values according to the needs of the user in Python. In this blog, we will learn how we can ignore multiple return values with the help of examples.

Table of Contents:

Ignoring a Return Value in Python

Suppose there is a function that returns multiple values in Python, but we need just one value, then we can use an underscore(“_”) to ignore the other returned values. Let’s understand this with an example:

Example to Ignore a returned value in Python:

Code:

Python

Output: 1,2

Explanation: Here we have ignored a returned value with the help of an underscore.

Ignoring All Return Values in Python

We can also ignore all the returned values in Python, with the help of not storing it in any variables.

Example to Ignore all returned values in Python:

Code:

Python

Output: Nothing

Explanation: Here we have returned the value but not stored it in any variable or array. So all the returned values are ignored here.

Ignoring Specific Return Values in Python

We can also ignore specific returned values in Python by using slicing. Let’s learn this with an example:

Example to Ignore specific returned value in Python:

Code:

Python

Output: 1 2

Explanation: Here with the help of the slicing operator, we have just stored the first two returned values, and the rest are ignored.

Conclusion

So far in this article, we have learned how to ignore a single or multiple returned values in Python. If you want to learn more about the Python Programming language, you must refer to our Python Course.

About the Author

Data Scientist | Technical Research Analyst - Analytics & Business Intelligence

Lithin Reddy is a Data Scientist and Technical Research Analyst with around 1.5 years of experience, specializing in Python, SQL, system design, and Power BI. Known for building robust, well-structured solutions and contributing clear, practical insights that address real-world development challenges.

EPGC Data Science Artificial Intelligence