Tuples as return values
2024-08-31 03:14:28
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:
Here is an example of a function that returns a tuple:
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
最新文章
- PHP 知识结构
- 重温Javascript第一章
- HDU1004 BALLO0N
- 使用 Fiddler2 进行接口测试的方法
- php Memcache
- mysql open files
- libaio under MIPS architecture /在mips架构下使用的libaio
- LDA 资料整理
- unity与ios交替
- 《无所不能的JavaScript编程系列:arguments 参数对象》
- OOP in Javascript
- iOS Xcode及模拟器SDK下载
- 搭建nuxtjs程序 —— 用户信息 or token怎么不丢失
- SAM维护的在线LCS
- linux tar解压命令
- Linux内核基础
- FileZilla建立服务器,命令行客户端
- python3-知识扩展扫盲易忘-generator的用法
- for循环实例2
- c++中“箭头(->;)”和“点号(.)”操作符的区别