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 trialEdward Parks
1,385 PointsNot Equivalent?!
How is it that: dict.updateValue("yetAnotherValue", forKey: 3) and dict[3] = "yetAnotherValue" not equivalent?
1 Answer
Steven Deutsch
21,046 PointsHey Edward Parks,
What exactly do you mean by them not being equivalent? Both are valid ways of updating a dictionary value for a specific key or creating a dictionary value for that key if it does not currently exist.
The difference is the that updateValue is a method that you call on your dictionary. Whereas, when you are using the assignment operator, =, you are assigning a new value to that dictionary directly.
They are just two different ways of accomplishing the same thing.
Hope this helps. Good Luck!