jquery教程

推荐列表 站点导航

当前位置:首页 > jquery > jquery教程 >

python中type()是什么意思

来源:网络整理  作者:网友投稿  发布时间:2020-12-28 23:05
jquery中文网为您提供python中type()是什么意思等资源,欢迎您收藏本站,我们将为您提供最新的python中type()是什么意思...

python中type()是什么意思

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 类名

bases 父类的元组

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()是什么意思的详细内容,更多请关注jquery中文网其它相关文章!

相关热词:

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!

本文地址: https://v30.fanwenzhu.com/jq/jc/10346.shtml

相关文章
最新文章
PHP识别相片是否是颠倒的 PHP识别相片是否是颠倒的

时间:2020-12-28

python编程有哪些ide python编程有哪些ide

时间:2020-12-28

python开发工程师是做什么 python开发工程师是做什么

时间:2020-12-28

php构造函数的作用 php构造函数的作用

时间:2020-12-28

php怎么跟数据库连接 php怎么跟数据库连接

时间:2020-12-28

php实现顺序线性表 php实现顺序线性表

时间:2020-12-28

Python多重继承中的菱形继 Python多重继承中的菱形继

时间:2020-12-28

php中break的作用 php中break的作用

时间:2020-12-28

Copyright © www.juheyunku.com      关于 | 合作 | 声明 | 联系 | 更新 | 地图 | Tags

python中type()是什么意思

2020-12-28 编辑:网友投稿

python中type()是什么意思

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 类名

bases 父类的元组

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()是什么意思的详细内容,更多请关注jquery中文网其它相关文章!

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供学习参考!
本文地址为 https://v30.fanwenzhu.com/jq/jc/10346.shtml

相关文章

风云图片

推荐阅读

返回jquery教程频道首页