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 trial

Python Python Basics (2015) Shopping List App Continue

Confusion over term

Though I know this has been covered before, whats the difference between "==" and "="?

1 Answer

Kieren Hughes
Kieren Hughes
2,851 Points

== is a comparison operator, whereas = is used for assignment.

For example:

a = 5 will assign the value 5 to the variable a.

2 == 3 will return False as 2 is not equal to 3

2 == 2 will return True

Hope that helps!

Thank you so much!!!

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Hey Reign,

see this code example as additional information.

// assignment
a = 5

// comparison
if a == 5:
    print("the value of a is 5".format(a))

Grigorij