关于Python的Type,Module,Class

简介:

关于Python的Type,Module,Class
Posted on 2007-07-13 by jeff

类在Python中只是一种数据类型.而任何东西都是对象应该是针对Type来说的,对象是Type的实例,而并不限于是类的实例.
要知道Python所支持的Type?那dir一下types就知道:
['BooleanType', 'BufferType', 'BuiltinFunctionType', 'BuiltinMethodType', 'ClassType', 'CodeType', 'ComplexType', 'DictProxyType',
'DictType', 'DictionaryType', 'EllipsisType', 'FileType', 'FloatType', 'FrameType', 'FunctionType', 'GeneratorType',
'GetSetDescriptorType', 'InstanceType', 'IntType', 'LambdaType', 'ListType', 'LongType', 'MemberDescriptorType', 'MethodType',
'ModuleType', 'NoneType', 'NotImplementedType', 'ObjectType', 'SliceType', 'StringType', 'StringTypes', 'TracebackType',
'TupleType', 'TypeType', 'UnboundMethodType', 'UnicodeType', 'XRangeType']
这些就是Python的数据实际类型了.嘿.
———————————————————
module?
一个Py文件可以看作是一个模块?一个包可以看作一个模块?当Import一个包的时候,所获得的东西只有init.py里面的东西?
import一个模块的时候会去执行此模块的文件中的程序?
全中!

再引用作者在知乎的评论
Python 的 type 和 object 之间是怎么一种关系?

结论
类(第二列的同学)在Python里面是一个对象(typeobject),对象是可以在运行时动态修改的
先来看看type和object:

>> object
<type 'object'>
>> type
<type 'type'>
关于Python的Type,Module,Class

自己的理解
A产生了B,B强大后也知道A是什么,A和B一样强大

这也出来了元类,第一列产生了元类



本文转自 liqius 51CTO博客,原文链接:http://blog.51cto.com/szgb17/2061663,如需转载请自行联系原作者

相关文章
|
Python
【Python】已解决:AttributeError: module ‘sys’ has no attribute ‘setdefaultencoding’
【Python】已解决:AttributeError: module ‘sys’ has no attribute ‘setdefaultencoding’
898 0
|
Python
python Module使用
【10月更文挑战第14天】 python Module使用
370 35
|
Linux Python
【Azure Function】Python Function部署到Azure后报错No module named '_cffi_backend'
ERROR: Error: No module named '_cffi_backend', Cannot find module. Please check the requirements.txt file for the missing module.
448 2
|
Go C++ Python
Python Tricks: String Conversion(Every Class Needs a ___repr__)
Python Tricks: String Conversion(Every Class Needs a ___repr__)
198 5
|
Python
[oeasy]python036_数据类型有什么用_type_类型_int_str_查看帮助
本文回顾了Python中`ord()`和`chr()`函数的使用方法,强调了这两个函数互为逆运算:`ord()`通过字符找到对应的序号,`chr()`则通过序号找到对应的字符。文章详细解释了函数参数类型的重要性,即`ord()`需要字符串类型参数,而`chr()`需要整数类型参数。若参数类型错误,则会引发`TypeError`。此外,还介绍了如何使用`type()`函数查询参数类型,并通过示例展示了如何正确使用`ord()`和`chr()`进行转换。最后,强调了在函数调用时正确传递参数类型的重要性。
207 3
|
Python
python布尔类型 (Boolean Type)
【8月更文挑战第3天】
683 8
|
Python
【Python】使用LogisticRegression出现错误: invalid type promotion
使用Python中的LogisticRegression时遇到TypeError: invalid type promotion错误的解决方法,指出错误原因是因为输入的DataFrame包含datetime类型的数据,并提供了通过删除datetime字段来解决此问题的步骤。
264 3
|
存储 Python 容器
Python中映射类型 (Mapping Type)
【8月更文挑战第2天】
999 2
|
数据处理 Python
【Python】解决tqdm ‘module‘ object is not callable
在使用tqdm库时遇到的“'module' object is not callable”错误,并给出了正确的导入方式以及一些使用tqdm的常见示例。
839 1
|
JSON 数据格式 Python
【python】解决json.dump(字典)时报错Object of type ‘float32‘ is not JSON serializable
在使用json.dump时遇到的“Object of type ‘float32’ is not JSON serializable”错误的方法,通过自定义一个JSON编码器类来处理NumPy类型的数据。
1082 1

推荐镜像

更多