02-07-2010, 08:02 AM
Yesterday I was working with some code, and I used the "is" instead of the "==" as following:
And it would just pass all of the if statements.... but when I replaced the "is" with the "==" it worked correctly. Any ideas? I thought they were the same operators?
Code:
import os
h = '[]>: '
while 1 > 0:
p = raw_input(h)
if (p is 'h?' or p is '--help'):
h = '[h?]>: '
print('\th?, --help\t\t\t-shows this list of commands\n\tpy?, --python\t\t\t-start interactive python in CLI\n\tpydle?, --python-idle\t\t\t')
if (p is 'py?' or p is '--python'):
h = '[py?]>: '
os.system('python2.6')
if (p is '--exit' or p is 'x?'):
os.system('clear') and os.system('cls')
print('Goodbye')
break
if (p is 'cs?' or p is '--clear'):
h = '[cs?]>: '
os.system('clear') and os.system('cls')
if (p is 'lst?' or p == '--list'):
h = '[lst?]>: '
print(os.listdir('.'))