python3:面向对象之成员变量(成员变量赋值为元组、字典)
一、python3源码
1 #!/usr/bin/python3 2 3 class data: 4 5 # python是“弱类型语言”,可以给“变量”赋予“任何类型的数值” 6 _name_array="" 7 _name_dict="" 8 def set_tuple(self, tuple_type): 9 self._name_array=tuple_type 10 11 def set_dict(self, dict_type): 12 self._name_dict=dict_type 13 14 def print_tuple(self): 15 print("print_tuple_out:", self._name_array) 16 17 def print_dict(self): 18 print("print_dict_out:", self._name_array) 19 20 21 22 mt = data() 23 tp=("fire", "water"); 24 dt={"name1":"fire", "name2":"water"} 25 26 mt.set_tuple(tp) 27 mt.print_tuple() 28 29 mt.set_dict(dt) 30 mt.print_dict()
二、源码运行结果
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/280808.html