-1

If I understand correctly, the is operator can take the place of ==.

Why when I write

if inpty == "exit":
    return

does the function exit, but when I write

if inpty is "exit":
    return

the function does not?

inpty is the value of the input.

Jacqlyn
  • 975
  • 3
  • 10
  • 38
  • 6
    Has been asked and explained here: http://stackoverflow.com/questions/1504717/python-vs-is-comparing-strings-is-fails-sometimes-why – sashkello Apr 29 '13 at 00:51

2 Answers2

3

is compares identity, whereas == compares equality.
In other words, a is b is the same as id(a) == id(b).

icktoofay
  • 122,243
  • 18
  • 242
  • 228
1

because in this case, the is operator is testing identity, not the value.

Pradeep Pati
  • 5,670
  • 2
  • 28
  • 42
Nomad101
  • 1,670
  • 11
  • 16
  • the question was why does is not evaluate to true? and that is because it is testing identity not value? – Nomad101 Apr 29 '13 at 01:58