"Good Z" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
| Hello,
| I am having problem in using is. Here is what i am doing.
|
| x=''
| if x is None or x is '':
|return 1
x is not the singleton value None, nor is it the newly created null string
object. It is up to the imp
'is' tests for identity (variable references the same memory location) while
'==' tests for equality. Though it's probably best to use 'is' with more
complex classes and not the simpler built-in types like integers.
See how 'is' works for lists below:
>>> l1 = [1,2,3,4]
>>> l3 = [1,2,3,4]
>>> l1
gns are NOT identical. They occupy two
different places and they are made from two totally different sets of atoms.
When you want to know if the stop sign on the near end is a stop sign,
you have to use the equality == operator. But if you want to check if
you are referring to exactly the one and onl
Good Z wrote:
Hello,
I am having problem in using is. Here is what i am doing.
Short answer: Use == for equality.Don't use "is". Ever!
(Especially if you are a newbie.)
Longer answer: In a dozen years of programming Python, the only time I
use "is" is when testing for something like
Hello,
I am having problem in using is. Here is what i am doing.
x=''
if x is None or x is '':
return 1
The above statement does not return value 1.
If i changed the above check to
if x == None or x == '':
return 1
Now it works fine.
Any idea. What is happening here. I am usin
italy wrote:
> Why doesn't this statement execute in Python:
>
> 1 == not 0
>
> I get a syntax error, but I don't know why.
>
> Thanks,
> Adam Roan
Of course, you would normally want to use != to see if something is not
equal to something else.
1 != 0
True
--
http://mail.python.org/mailman/lis
In <[EMAIL PROTECTED]>, italy wrote:
> Why doesn't this statement execute in Python:
>
> 1 == not 0
>
> I get a syntax error, but I don't know why.
`==` has a higher precedence than `not` so Python interprets it as::
(1 == not) 0
This works::
>>> 1 == (not 0)
True
Ciao,
Marc
"not" has a lower priority than non-Boolean operators, so not a == b is
interpreted as not (a == b), and a == not b is a syntax error.
http://docs.python.org/lib/boolean.html
--
http://mail.python.org/mailman/listinfo/python-list
> Why doesn't this statement execute in Python:
>
> 1 == not 0
>
> I get a syntax error, but I don't know why.
This does: 1 == (not 0)
I presume Python treats it like
1 (== not) 0
Which is a SyntaxError
greets,
Marek
--
http://mail.python.org/mailman/listinfo/python-list
italy wrote:
Why doesn't this statement execute in Python:
1 == not 0
I get a syntax error, but I don't know why.
Because == has higher precedence than 'not', so you are asking for
(1 == not) 0
Try
>>> 1 == (not 0)
True
Kent
Thanks,
Adam Roan
--
http://mail.python.org/mailman/listinfo/python-list
Why doesn't this statement execute in Python:
1 == not 0
I get a syntax error, but I don't know why.
Thanks,
Adam Roan
--
http://mail.python.org/mailman/listinfo/python-list
11 matches
Mail list logo