python言語の3つの奇妙な戻り値

1028 ワード

公衆番号から見た、記録した
d = {}
d[5] = "test1"
d[5.0] = "test2"
d["5"] = "test3"

print(d[5])
print(d[5.0])
print(d["5"])


print(5 == 5.0)

print(hash(5) == hash(5.0))


# python   key              hash           

# test2
# test2
# test3
# True
# True



def test():
    try:
        return "fun"
    finally:
        return "try"

res = test()
print(res)
# try


#      finally     ,             return    

class test(object):
    def __init__(self):
        print("i")

    def __del__(self):
        print("d")


print(test()  == test())


print(id(test()) == id(test()))


# i
# i
# d
# d
# False
# i
# d
# i
# d
# True