python barh python bar函数变化_python



装饰器之函数即变量

1、在第一次执行中,由于bar函数未在python内存中定义,所以不能正常执行

def foo():print('in the foo')bar()foo()


python barh python bar函数变化_bar函数 python_02


2、由于bar和foo使用之前已经在python内存中被定义,在调用时已经被python进行了解释,所以不管函数是谁在前或者在后定义,都能够正常执行。

def bar():print('in the bar')def foo():print('in the foo')bar()foo()————————————————————————————————————def foo():print('in the foo')bar()def bar():print('in the bar')foo()


python barh python bar函数变化_bar函数 python_03


python barh python bar函数变化_引用计数_04


3、bar是先被执行的,而在python内存中bar为被定义,所以无法执行

def foo():print('in the foo')bar()foo()def bar():print('in the bar')


python barh python bar函数变化_bar函数 python_05


python变量内存回收机制

  1. Python内存回收的基石是引用计数,“当一个对象的引用被创建或复制时,对象的引用计数加1;当一个对象的引用被销毁时,对象的引用计数减1”,如果对象的引用计数减少为0,将对象的所占用的内存释放。

结语

感谢阅读,欢迎在评论区中发表自己不同的观点,若有其他问题请在评论区留言,喜欢的朋友请多多关注转发支持一下。


python barh python bar函数变化_python barh_06