码迷,mamicode.com
首页 > 其他好文 > 详细

类的两种定义

时间:2018-11-15 22:28:48      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:pre   %s   __init__   hello   sel   print   定义   class   obj   


# class Foo(object):
# def __init__(self, name):
# self.name = name
#
#
# f = Foo("alex")
# print(type(f))
# print(type(Foo))


def func(self):
print(‘hello %s‘ %self.name)
def __init__(self,name,age):
self.name = name
self.age = age

Foo = type(‘Foo‘, (object,), {‘talk‘: func,
‘__init__‘:__init__})
f = Foo("Chrn",22)
f.talk()
print(type(Foo))

类的两种定义

标签:pre   %s   __init__   hello   sel   print   定义   class   obj   

原文地址:https://www.cnblogs.com/rongye/p/9965974.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!