
type()是一个内建的获取变量类型的函数。
type()函数有两个用法,当只有一个参数的时候,返回对象的类型。当有三个参数的时候返回一个类对象。
语法:
type(object) type(name, bases, dict)
具体用法:
一个参数
type(object)
返回一个对象的类型,如:
In [1]: a = 10 In [2]: type(a) Out[2]: int
三个参数
tpye(name, bases, dict)
name 类名
立即学习“Python免费学习笔记(深入)”;
bases 父类的元组
在整本书中我们所涉及许多的Flex框架源码,但为了简洁,我们不总是显示所指的代码。当你阅读这本书时,要求你打开Flex Builder,或能够访问Flex3框架的源码,跟随着我们所讨论源码是怎么工作及为什么这样做。 如果你跟着阅读源码,请注意,我们经常跳过功能或者具体的代码,以便我们可以对应当前的主题。这样能防止我们远离当前的主题,主要是讲解代码的微妙之处。这并不是说那些代码的作用不重要,而是那些代码处理特别的案例,防止潜在的错误或在生命周期的后面来处理,只是我们当前没有讨论它。有需要的朋友可以下载看看
0
dict 类的属性方法和值组成的键值对
返回一个类对象:
# 实例方法
def instancetest(self):
print("this is a instance method")
# 类方法
@classmethod
def classtest(cls):
print("this is a class method")
# 静态方法
@staticmethod
def statictest():
print("this is a static method")
# 创建类
test_property = {"name": "tom", "instancetest": instancetest, "classtest": classtest, "statictest": statictest}
Test = type("Test", (), test_property)
# 创建对象
test = Test()
# 调用方法
print(test.name)
test.instancetest()
test.classtest()
test.statictest()输出结果:
tom this is a instance method this is a class method this is a static method
推荐教程:python教程
以上就是python中type()是什么意思的详细内容,更多请关注php中文网其它相关文章!
python怎么学习?python怎么入门?python在哪学?python怎么学才快?不用担心,这里为大家提供了python速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号