Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialBill Talkington
11,840 Pointsb = a?
At 3:28, you say copy 'c' to 'b', but the video shows 'a' being copied to 'b' after is has been updated to equal 2.
Did I catch that right?
1 Answer
Robert Richey
Courses Plus Student 16,352 PointsHi Bill,
Kenneth is just using an example for how other programming languages swap the value of variables - by having to create a temporary third variable. Here, I'm calling the temporary variable tmp
instead of c
just to more easily illustrate the idea.
# just an example, don't actually do this in python
# the setup
a = 1
b = 2
# the swap
tmp = a # tmp == 1
a = b # a == 2
b = tmp # b == 1
# the finale
a = 2
b = 1
# instead, do this
a, b = b, a
Bill Talkington
11,840 PointsBill Talkington
11,840 PointsThanks for the reply.
I understand what he was explaining. However, what is shown and what is said in the video could come off as incongruent to a beginner.
The temporary variable in the video (c) is never visually copied to b in code form (the arrow implicitly does).
The end result that is shown is correct, I was just worried about a beginner trying to execute exactly what is shown on the screen. Maybe I'm just being too picky! ;)
Robert Richey
Courses Plus Student 16,352 PointsRobert Richey
Courses Plus Student 16,352 PointsAh, yes, I see what you mean. I agree, the pseudo-code was a bit confusing to me also, but since I already understood variable swapping I really didn't think much about it.