For Python, everything is an object, and all the data stored in the program is an object, and the object is created based on the class. This article mainly describes the Python object data type, the need for friends can refer to the following
For Python, everything is an object, all the data stored in the program is an object, and the object is created based on the class
The computer can process more than the numerical value, but also can deal with text, graphics, audio, video, web and other kinds of data, different data, need to define different data types.
Class refers to a custom type, and type refers to a built-in type. Both represent data types, and they are called different.
Each object has an identity, a type, and a value, which refers to the pointer (an in-memory address) where the object is in memory, and the built-in function ID () returns the identity of an object. The variable name is the name that refers to the specific location.
Instantiation: Creating a specific type of object
After an instance is created, its identity and type cannot be changed
If the object value can be modified, it is called a mutable object
If the object value is not modifiable, it is called an immutable object
Container: An object contains a reference to another object, such as a list.
Python is a strongly typed language in which the type of object determines the operation that the object can participate in or the method it supports, that is, the method exists in the class, and the function in the object is found in the class.
Most objects have a large number of unique data properties and methods
Properties: Object-related values, such as variable names
Method: A function that will perform certain operations on an object when called
>>> name= ' test ' >>> name.upper ()--method test>>> num = 1>>> print (num.real)--Properties Help ( Type)--View what methods or properties of a type >>> help (Type.func)--Find the usage of a method >>> Help (Str.find) Use the dot (.) operator to access the properties and methods print (obj)--See which class the object was created by >>> from twisted.internet import reactor>>> print ( Type (reactor))
Core data types
Numbers: Int,long,float,complex,bool (0:false, 1:true)
Character: Str,unicode
Listing: List
Tuples: Tuple
Dictionary: Dict
Files: File
Other: Set (set), Frozeset, class type, None