网络编程
位置:首页>> 网络编程>> Python编程>> 对python模块中多个类的用法详解

对python模块中多个类的用法详解

作者:小妖精Fsky  发布时间:2021-03-17 17:27:21 

标签:python,模块,类

如下所示:


import wuhan.wuhan11

class Han:
def __init__(self, config):
 self.batch_size = config.batch_size
 self.num_steps = config.num_steps

class config:
batch_size = 10
num_steps = 50

if __name__ == '__main__':
han = Han(config)
print(han.batch_size)
print(han.num_steps)

输出结果:

/home/ubuntu/workspace/pythondemo/env/bin/python /home/ubuntu/workspace/BioEvent/wuhan/Han.py
10
50

Process finished with exit code 0

刚学习Python,所以一点点学会的东西都想要记载怕秀逗脑袋瓜记不住:

感悟:

1. batch_size和num_steps可以理解成类Han的成员变量

2. class 类型 可以不用实例化直接作为参数使用

3. 模块中可以有多个类

来源:https://blog.csdn.net/appleml/article/details/53729293

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com