1、局部变量
只能在函数或者代码段内使用的变量。函数或者代码一旦结束,局部变量的生命周期也就结束。
# 局部变量def fun(): local=1 print(local)fun()#函数调用完,即local释放内存注:python创建的变量就是一个对象,python会管理变量的生命周期。python对变量的回收采用的是垃圾回收机制。2、全局变量 能够被不同的函数、类或文件共享的变量,在函数之外定义的变量都可以称为全局变量。全局变量可以被文件内部的任何函数和外部文件访问。