Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"==" and "is" in Python
#2
It seems to be the characters used in the commands(-- and ?). I guess "is" doesn't evaluate those. Here is an example using and interactive session with python.
Code:
>>> p = 'h'
>>> if p is 'h':
    print 'hi'

    
hi
>>> p = 'h?'
>>> if p is 'h?':
    print 'hi'

    
>>> p = '--h'
>>> if p is '--h':
    print 'hi'

    
>>> if p == '--h':
    print 'hi'

    
hi
>>>
I guess it's just safer to use "==".
[Image: izsyo6.jpg]


Reply


Messages In This Thread
"==" and "is" in Python - by Canoris - 02-07-2010, 08:02 AM
RE: "==" and "is" in Python - by uber1337 - 02-07-2010, 03:55 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Help Dεlluzion 3 2,006 09-30-2019, 12:59 AM
Last Post: samsmith001
  Simple Python Python Compiler Canoris 21 9,177 06-01-2011, 06:30 PM
Last Post: Filefinder
  Python 2 vs 3? Jake 8 2,662 12-11-2010, 04:13 PM
Last Post: Bursihido
  Python help Kharnage 2 894 02-12-2010, 09:07 PM
Last Post: Kharnage
  I Need Help with Python Kharnage 19 4,433 02-06-2010, 08:58 AM
Last Post: Kharnage

Forum Jump:


Users browsing this thread: 1 Guest(s)