当前位置:主页 > 软件编程 > Python代码 >

Python实现结构体代码实例

时间:2021-03-12 09:54:14 | 栏目:Python代码 | 点击:

这篇文章主要介绍了Python实现结构体代码实例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下

# python 使用类创建结构体
class Myclass(object):
  class Struct(object):
    def __init__(self, name, age, job):
      self.name = name
      self.age = age
      self.job = job

  def make_struct(self, name, age, job):
    return self.Struct(name, age, job)

myclass = Myclass()
test1 = myclass.make_struct('xsk', '22', 'abc')
test2 = myclass.make_struct('mtt', '23', 'def')

print test1.name
print test1.age
print test1.job
print test2.name
print test2.age
print test2.job

您可能感兴趣的文章:

相关文章