Python Forum

Full Version: Identity Operators and basic Forum etiquette.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey fellow users! I just started learning Python a few weeks ago via the 'Beginning Programming wit Python for Dummies' book. I am currently on operators. And for this thread, I am currently on the 'Identity Operators': is, not. And I have a basic understanding. If I'm correct, say: 'type(2) int' results in 'True' because the 'type' of data '2' is an integer.
But I tried just typing:

'int is True'

False

Also I tried:

'int is False'

False

Why is that?

Is this because if 'is' in the statement 'int is True' is an operator, and 'int' and 'True' are the operands, the left operand is always False? So, 'int(False) is True(True) results in False because 'int is False', not True. But then what about 'int is False'? Why does that result in False?

I hope this makes sense.

Also, I'm new to this forum, and forums in general. And this is actually my first thread. So, a few questions.
1. Is this the right topic (Python Forum section) to put this thread?
2. What are some other: techniques, tips, lessons I could and should start learning in regard to Python, but specifically operators for now.
3. Is there something I should be learning rather than operators?
4. Do I have the right forum "syntax"? Is this thread the right format, and how I could improve it? Am I using the right terminology?

Thanks, for all the support I've already seen by users on this Forum. I am really excited to invest in Python and its community and learn more!
The is operator is looking for two objects that are exactly the same. Technically, this means they are stored in the same location. 'int is True' being False means that the int class and the True constant are stored in different locations. type(2) is int returns True, because the left hand returns int, and int is stored in the same place as int. Note that type testing is usually done with the built-in function isinstance().

If you got a book, keep reading the book. If you want to post code here, check out the BBCode link in my signature below on how to do it correctly.
Thanks ichabod801! This is very clarifying, but also raises a few good questions! I'll go do my homework, but I might be back soon with some more questions. Thank you! And thanks for the tip on my book, and for the BBCode link. I'll check it out.
I'll add to the advice by saying, if you are just learning, be sure you learn Python 3 not Python 2. I suggest you use the latest version, currently 3.6.3, if possible.