Files
python3-cookbook/source/c01/p01_unpack_sequence_into_separate_variables.rst

18 lines
658 B
ReStructuredText
Raw Normal View History

2014-08-20 16:13:20 +08:00
===============================
解压序列赋值给多个变量
===============================
----------
问题
----------
You have an N-element tuple or sequence that you would like to unpack into a collection of N variables.
----------
解决方案
----------
Any sequence (or iterable) can be unpacked into variables using a simple assignment operation. The only requirement is that the number of variables and structure match the sequence. For example:
----------
讨论
----------
Unpacking actually works with any object that happens to be iterable, not just tuples or lists. This includes strings, files, iterators, and generators. For example: