-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.

jfa
  • 1,047
  • 3
  • 13
  • 39
  • 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
  • 126,289
  • 21
  • 250
  • 231
1

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

Pradeep Pati
  • 5,779
  • 3
  • 29
  • 43
Nomad101
  • 1,688
  • 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