In Python, you can swap the values of two variables using the following syntax
a, b = b, a
How to do this in Dart?
Python tuples are immutable means that they can not be modified in whole program. Packing and Unpacking a Tuple: In Python, there is a very powerful tuple assignment feature that assigns the right-hand side of values into the left-hand side. In another way, it is called unpacking of a tuple of values into a variable.
Unpacking in Python refers to an operation that consists of assigning an iterable of values to a tuple (or list ) of variables in a single assignment statement. As a complement, the term packing can be used when we collect several values in a single variable using the iterable unpacking operator, * .
Python style tuple unpacking is not supported in Dart. Neither is the assignment of multiple variables as you have in your example. If it is the swap you are after, you could always just do the following:
var a = 10, b = 5, temp;
temp = a;
a = b;
b = temp;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With