* An assignment to all of the elements in a tuple using a single assignment statement.
* Python has a very powerful tuple assignment feature that allows a tuple of variables on the left of an assignment to be assigned values from a tuple on the right of the assignment. The left side is a tuple of variables; the right side is a tuple of values.
* Each value is assigned to its respective variable.
* All the expressions on the right side are evaluated before any of the assignments.
* This feature makes tuple assignment quite versatile.
* Naturally, the number of variables on the left and the number of values on the right have to be the same.
Example : swap of two variables
Tuple packing & Tuple unpacking :
* In tuple packing, the values on the left side are packed together in a tuple. In tuple unpacking, the values on the right are unpacked in the variables/names.
No comments:
Post a Comment