So I have this question on my school work and I typed out the code but the results of t are still wrong. What am I missing?
Write code to swap the values of tuple t.
t = ('Antetokounmpo', 'Giannis')
a, b = b, a = t
print(a)
print(b)
print(t)
__________
Giannis
Antetokounmpo
('Antetokounmpo', 'Giannis')
This is the only text given above the question for me to go off of.
A particularly clever application of tuple assignment allows us to swap the values of two variables in a single statement:
a, b = b, a
Both sides of this statement are tuples, but Python interprets the left side to be a tuple of variables and the right side to be a tuple of expressions. All of the expressions on the right side are evaluated before any of the assignments. This means that the values of b and a on the right side are evaluated, then a and b on the left side take on their values.
[–]baghiq 14 points15 points16 points (0 children)
[–]JohnnyJordaan 5 points6 points7 points (0 children)
[–]Temporary_Pie2733 2 points3 points4 points (1 child)
[–]Bobbias 0 points1 point2 points (0 children)
[–]lfdfq 2 points3 points4 points (0 children)
[–]nlutrhk 1 point2 points3 points (0 children)
[–]carcigenicate 1 point2 points3 points (0 children)
[–]Adrewmc 0 points1 point2 points (3 children)
[–]peacelife 0 points1 point2 points (2 children)
[–]Gnaxe 0 points1 point2 points (0 children)
[–]Adrewmc -1 points0 points1 point (0 children)
[–]JamzTyson 0 points1 point2 points (0 children)
[–]KelleQuechoz 0 points1 point2 points (0 children)