Customize Consent Preferences

We use cookies to help you navigate efficiently and perform certain functions. You will find detailed information about all cookies under each consent category below.

The cookies that are categorized as "Necessary" are stored on your browser as they are essential for enabling the basic functionalities of the site. ... 

Always Active

Necessary cookies are required to enable the basic features of this site, such as providing secure log-in or adjusting your consent preferences. These cookies do not store any personally identifiable data.

No cookies to display.

Functional cookies help perform certain functionalities like sharing the content of the website on social media platforms, collecting feedback, and other third-party features.

No cookies to display.

Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics such as the number of visitors, bounce rate, traffic source, etc.

No cookies to display.

Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.

No cookies to display.

Advertisement cookies are used to provide visitors with customized advertisements based on the pages you visited previously and to analyze the effectiveness of the ad campaigns.

No cookies to display.

忽略python多重返回值

我们可以根据Python中用户的需求忽略一个或多个返回值。在此博客中,我们将学习如何在示例的帮助下忽略多个返回值。

目录:

忽略python中的回报值

假设有一个函数可以返回Python中的多个值,但是我们只需要一个值,然后我们可以使用下划线(“ _”)来忽略其他返回的值。让我们以一个例子理解这一点:

忽略python中返回值的示例:

代码:

def get_values():
    return 1, 2, 3

intellipaat1, intellipaat2, _ = get_values()
print(intellipaat1, intellipaat2)  

输出:1,2

解释: 在这里,我们在下划线的帮助下忽略了返回的值。

忽略python中的所有返回值

我们还可以在不将其存储在任何变量中的帮助下,忽略Python中的所有返回值。

忽略Python中所有返回值的示例:

代码:

def get_values():
    return 1, 2, 3

get_values()

输出: 没有什么

解释: 在这里,我们返回了该值,但没有将其存储在任何变量或数组中。因此,在这里忽略了所有返回的值。

忽略python中的特定返回值

我们还可以使用切片忽略Python中的特定返回值。让我们以一个例子来学习:

忽略python中特定返回值的示例:

代码:

def get_values():
    return 1, 2, 3, 4, 5

a, b = get_values()[:2]
print(a, b)  

输出: 1 2

解释: 在切片操作员的帮助下,我们刚刚存储了前两个返回的值,其余的值却被忽略了。

结论

到目前为止,在本文中,我们学会了如何忽略Python中的单个或多个返回值。如果您想了解有关Python编程语言的更多信息,则必须参考我们的Python课程。

Related Posts

AI助手的下一个演变

AI助手的下一个演变

人工智能领域(AI)正在迅速发展,Google的领域 …

Whatsapp Bharat Yatra到达艾哈迈达巴德,为小型企业提供了数字增长

艾哈迈达巴德(古吉拉特邦) [India],3月13日…

IBM和巴斯克政府宣布计划在西班牙的IBM-Euskadi量子计算中心安装欧洲第一个IBM量子系统。

IBM和巴斯克政府宣布计划在西班牙的IBM-Euskadi量子计算中心安装欧洲第一个IBM量子系统。

该帖子最初发表在此网站上 IBM量子系统二由公用事业规…

芒果不起作用? 10个经过验证的修复程序,让您再次阅读

芒果不起作用? 10个经过验证的修复程序,让您再次阅读

关键要点 当流行的漫画网站Mangago无法正常工作时…

忍者时间代码(2025年3月)

忍者时间代码(2025年3月)

受到心爱的动漫系列的启发 火影忍者,Ninja Tim…

MWC25综述:电信与技术

MWC25综述:电信与技术

正如在巴塞罗那MWC25上显而易见的那样,移动世界大会…