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 trialRobert Peters
3,728 PointsPython, 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
Idan Melamed
16,285 PointsI also found this: http://stackoverflow.com/questions/14247373/python-none-comparison-should-i-use-is-or
Maybe you can make more sense out of it then I did :-)
Idan Melamed
16,285 PointsFrom 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 ==...
diegoholt
1,076 PointsYeah I'd love some clarification here too!
Robert Peters
3,728 PointsRobert Peters
3,728 Pointscheers 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