a=1
b=1
c=1
class Person(object):
def __init__(self,name,age):
self.name="wwl"
self.age=18
def __eq__(self, other):
return self.name==other.name and self.age== other.age
#p1=Person()
#p2=Person()
#p1 = Person("ddl", 23)
#p2 = Person("ddl", 23)
num1=10
if __name__=="__main__":
print(bin(num1)) #转化成二进制 0b1010
print(oct(num1)) #转化成八进制 0o12
print(hex(num1)) #转化成16进制 0xa
print(a is b) # True
print(a==b) # True
print(id(a)) #输出a的内存地址 1925939312
print(id(b)) #输出b的内存地址 1925939312
print(id(c)) #输出c的内存地址 1925939312
p1=Person("ddl",23)
p2=Person("ddl",23)
print(p1==p2) # True
print(p1 is p2) # False
print(id(p1)) #输出p1的内存地址 2528646842016
print(id(p2)) #输出p2的内存地址 2528646841736
print(id(p1)) #输出p1的内存地址 2528646842016
print(id(p2)) #输出p2的内存地址 2528646841736
print(p1==p2) # True
print(p1 is p2) # False
总结常量,相同数值的内存地址一样,引用对象的相同内容的地址不同。python的is和Java的= =的作用一样,而Python的= =和Java的equals作用一样