1.类变量
定义:类变量被所有的类实例共享,通常都定义在类声明下面,他被所有的类实例共享
所在位置:类中,函数声明外
什么时候加载:在文件导入到其他文件时加载
如何在函数中调用:在类函数中必须使用ClassName.class_variable = ***来赋值,否则,你创建的只是一个实例变量,举例如下:
class Test(object):
class_variable = 1
def func(self):
Test.class_variable = 2 (正确)
class_variable = 2(错误,这是一个实例变量)
存在时间:一个到该脚本结束?
python官网的链接:https://www.python-course.eu/python3_class_and_instance_attributes.php
2.实例变量
所在位置:class内,self修饰
3.局部变量:在函数的class内,(不加self)
定义:在一个函数中,一个变量第一次出现,并在=的前面,那么他是一个实例变量
4.全局变量:在模块内,函数和类外面
2018年6月3日星期日
订阅:
博文评论 (Atom)
leetcode 17
17. Letter Combinations of a Phone Number Medium Given a string containing digits from 2-9 inclusive, return all possible l...
-
ptb的代码可以详见gitlab上的tensorflow/models/tutorials下,本文只详解他的数据前处理和模型部分。 1.运行 首先说一下他的运行 ,下载数据集: http://www.fit.vutbr.cz/~imikolov/rnnlm/simple-e...
-
写在开头,以下是我在过程中遇到的一些问题 1.关于KNN算法代码里的一些问题 1.1关于numpy的sum用法 Check out the documentation for numpy.sum, paying particular attention to the ...
-
首先安装openfst,如果你想继续安装pyfst的话,你需要安装openfst1.3.3的版本,因为pyfst始终不跟新,只支持到openfst1.3.3 打开openfst主页,下载1.3.3的版本 http://www.openfst.org/twiki/bin/view...
没有评论:
发表评论