Python Forum
Identity Operators and basic Forum etiquette.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Identity Operators and basic Forum etiquette.
#1
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!
Reply
#2
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
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.
Reply
#4
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.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Use of if - and operators Pedro_Castillo 1 487 Oct-24-2023, 08:33 AM
Last Post: deanhystad
  Mixing Boolean and comparison operators Mark17 3 1,404 Jul-11-2022, 02:20 AM
Last Post: perfringo
  Magic Method Arithmetic Operators ClownPrinceOfCrime 3 2,312 Jan-10-2021, 03:24 PM
Last Post: ndc85430
  wrong forum, please delete. reposted in correct forum. woodmister 0 1,584 Jan-04-2021, 11:17 PM
Last Post: woodmister
  Class and Operators in Python rsherry8 1 1,985 May-27-2020, 07:09 PM
Last Post: buran
  Trying Comparison Operators PythonGainz 3 2,700 Mar-28-2020, 10:46 AM
Last Post: PythonGainz
  Mathematical Operators in String AgileAVS 1 2,377 Mar-04-2020, 04:14 PM
Last Post: Gribouillis
  A doubt with 'in' and 'not in' operators with strings newbieAuggie2019 7 3,583 Oct-23-2019, 03:11 PM
Last Post: perfringo
  understanding exponential and bitwise operators srm 1 2,043 Jun-15-2019, 11:14 AM
Last Post: ThomasL
  please help with this question about using operators to multiply a string? GilesTwigg 3 4,371 Feb-27-2019, 04:13 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020