Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

This technique is normally used when you receive an object by poking a dictionary or invoking a method; if the identity of var1 and var2 is the same, then they are obviously equal--because they are the same object.

"==" example:
Code Block
/*
"""
True,
False,
True!
"""*/
a = 0
b = 0
c = 4

print a == b
print c == b
print a == 0
"isa" example:
Code Block
/*
"""
Prints out...
True,
True,
False!
"""*/
class Food:
	pass

class Sandwich(Food):
	pass

hamAndSwiss = Sandwich()

print hamAndSwiss isa Food
print hamAndSwiss isa Sandwich
print hamAndSwiss isa int
"is" example:
Code Block
/*
"""
prints,
True,
False
"""*/
var1 = "hello, world!"
var2 = var1
var3 = "hey, carl!"
print var1 is var2
print var1 is var3 //2 different objects pointed at!