Forpython, everything isobject, all data stored in the program are objects, and objects are created based on classes. This article mainly introduces thedata types of Python objects. Friends who need it can refer to it
For Python, everything is an object, and all data stored in the program is an object. Object Class-based creation
Computers can process far more than just numerical values. They can also process various data such as text, graphics,audio,video, web pages, etc. Different For data, different data types need to be defined.
classrefers to a custom type, and type refers to a built-in type. Both represent data types, the names are just different
Each object has an identity, a type and a value. The identity refers to the pointer of the location of the object in memory (the address in memory),Built-in functionid() can return the identity of an object.Variable nameisReferenceThe name of this specific location
Instantiation: Create an object of a specific type
After the instance is created, its identity and type Immutable
If the object value can be modified, it is called a mutable object
If the object value cannot be modified, it is called an immutable object
Container: An object contains a pair ofothersReference of object, such as list.
Python is a strongly typed language. The type of an object determines the operations that the object can participate in or the methods it supports. That is, the methods exist in the class, and the functions in the object are all found in the class.
Most objects have a large amount of unique dataProperties and methods
Properties: Values related to the object, such as variable names
Methods: When called, Functions that perform certain operations on objects
>>> name='test' >>> name.upper() --方法 TEST >>> num = 1 >>> print(num.real) --属性 help(type) -- 查看某个类型有哪些方法或属性 >>> help(int) help(type.func) -- 查找某个方法的用法 >>> help(str.find) 使用点(.)运算符可以访问属性和方法 print(type(obj)) -- 查看对象由哪个类创建的 >>> from twisted.internet import reactor >>> print(type(reactor))
Core data types
Numbers: int, long,float,complex,bool (0:False, 1:True )
Character: str,unicode
List:list
Tuple: tuple
Dictionary: dict
File:file
Others:set(set),frozeset, Class type, None
The above is the detailed content of A detailed introduction to data types in Python objects. For more information, please follow other related articles on the PHP Chinese website!