Why is the id of a Python class not unique when called quickly?

前端 未结 6 1169
花落未央
花落未央 2020-11-22 15:29

I\'m doing some things in Python (3.3.3), and I came across something that is confusing me since to my understanding classes get a new id each time they are called.

6条回答
  •  佛祖请我去吃肉
    2020-11-22 16:06

    Try this, try calling the following:

    a = someClass()
    for i in range(0,44):
        print(someClass())
    print(a)
    

    You'll see something different. Why? Cause the memory that was released by the first object in the "foo" loop was reused. On the other hand a is not reused since it's retained.

提交回复
热议问题