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) Python for Beginners First Quiz

omar talaat
PLUS
omar talaat
Courses Plus Student 171 Points

in quiz 1 why variable = value why not double the equal sign as i assign a value like 5 to my variable

i assign a value like any number to my variable so why not double equal

2 Answers

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,720 Points

The double equal is a test for logical/value equivalence. If you use it by itself and x hasn't been assigned a value, it will throw a name error. x = 2 assigns a value to variable x. After it is assigned x==2 returns the logical/value test of equivalence to 2.

I hope this helps your understanding.

Python 2.7.12 (default, Nov 19 2016, 06:48:10)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> x == 2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'x' is not defined
>>> x = 2
>>> x
2
>>> x == 2
True
>>>

one = , meaning assign in python two ==, meaning check if equal to...

these two meanings (= for assign, and == for check if equal) are true for most programming languages

three ===, has no meaning in python but in JS for check if value is equal and also if it the same type