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) Logic in Python Weighing Your Options

Python, is vs ==

Does anyone know which is more secure to use for checking if a variable is None in Python, A == None or A is None, couldn't tell which was being referred to at the end of the vid. And if possible, give a (VERY) simple explanation as to how the other creates a security flaw? I realise that may be well beyond me, for now, but... curiosity.

3 Answers

cheers pal, yeah its a pretty good description thanks. maybe I misunderstood him in that he didn't mean it's actually 'unsafe' to use the ==, just that it's 'safer' to use 'is' in these circumstances as in it's 'correct'. Thanks for the help

Idan Melamed
Idan Melamed
16,285 Points

From this stackoverflow thread:

Quoting Python's Coding Style Guidelines - PEP-008 (jointly defined by Guido himself), Comparisons to singletons like None should always be done with is or is not, never the equality operators.

I'm still not exactly sure why this is preferable then ==...

Yeah I'd love some clarification here too!