码迷,mamicode.com
首页 > 其他好文 > 详细

Tuples as return values

时间:2014-07-19 18:31:23      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   2014   io   for   

Strictly speaking, a function can only return one value, but if the value is a tuple, the effect is the same as returning multiple values. For example, if you want to divide two integers and compute the quotient and remainder, it is inefficient to compute x/y and then x%y. It is better to compute them both at the same time. The built-in function divmod takes two arguments and returns a tuple of two values, the quotient and remainder. You can store the result as a tuple:

bubuko.com,布布扣                       

Here is an example of a function that returns a tuple:

bubuko.com,布布扣 

max and min are built-in functions that find the largest and smallest elements of a sequence. max_min computes both and return a tuple of two values.

 

 

from Thinking in Python

Tuples as return values,布布扣,bubuko.com

Tuples as return values

标签:style   blog   http   2014   io   for   

原文地址:http://www.cnblogs.com/ryansunyu/p/3855002.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!