Python 一些内置函数的总结~~~~

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-01 02:46:34

1. type()

两种用法

a. 当传入参数为一个时,返回值为参数的类型

b. 当传入参数为三个时,type(name, bases, dict)
name: 类名
bases: 继承父类的元组,可继承也可不继承
dict: 构成类属性和方法的键值对(方法在外部定义,直接引用).
返回一个类对象
class TestBasic(object):
    @staticmethod
    def parent():
        print "this is parent method"


def child(self):
    print "this is child method"


test_property = {"name": "heihei", "child": child}

Test = type("Test", (TestBasic,), test_property)

test = Test()

print test.name
test.child()
test.parent()

运行结果:

heihei
this is child method
this is parent method

 

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!