当前位置: 移动技术网 > IT编程>脚本编程>Python > 对python模块中多个类的用法详解

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

2019年03月21日  | 移动技术网IT编程  | 我要评论

cctv3万家邀明月,朱思芸,山东金属网

如下所示:

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. 模块中可以有多个类

以上这篇对python模块中多个类的用法详解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网