python中的变量生命周期

Posted redguardtoo

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python中的变量生命周期相关的知识,希望对你有一定的参考价值。

运行以下代码就可以知道了,有点类似于boost::shared_ptr

class a:
 def __init__(self):
  print "a()"
 def __del__(self):
  print "~a()"
  
class b:
 def __init__(self):
  print "b()"
 def hello(self):
  print "hello world"
 def __del__(self):
  print "~b()"

if __name__ == '__main__':
 print "let's begin test:"
 c=a()
 c=b()
 print "after c=b()"
 d=c
 print "after d=c"
 c.hello()
 d.hello()
 print c,d
 del c
 print "after del c"
 print d
 del d
 print "after del d"
 

以上是关于python中的变量生命周期的主要内容,如果未能解决你的问题,请参考以下文章

C语言中,哪种存储类的作用域与生命周期是不一致的?

目标c线程中的线程变量生命周期

java 静态变量生命周期(类生命周期)

java 静态变量生命周期(类生命周期)(转)

Vue.js生命周期的详细介绍

Eclipse 调试器变量生命周期视图