Data types in Python objects
- 2020-06-01 10:07:45
- OfStack
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
Computers can process far more than just Numbers. They can also process text, graphics, audio, video, web pages, and other kinds of data. Different types of data need to be defined.
class for custom types, type for built-in types. They both represent data types, and they're just called differently
Each object has an identity, a type, and a value. An identity is a pointer to the object's location in memory (the address in memory). 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 objects of a specific type
Once an instance is created, its identity and type are immutable
If the object value can be modified, it is called a mutable object
An object whose value cannot be modified is called an immutable object
Container: an object contains references to other objects, such as lists.
python is a strongly typed language. The type of the object determines the operations that the object can participate in or the methods it supports.
Most objects have a large number of unique data properties and methods
Properties: values associated with an object, such as variable names
Method: a function that will perform some operation on the object when called
>>> name='test'
>>> name.upper() -- methods
TEST
>>> num = 1
>>> print(num.real) -- attribute
help(type) -- See what methods or properties a type has
>>> help(int)
help(type.func) -- Find the usage of a method
>>> help(str.find)
Using point ( . The) operator can access properties and methods
print(type(obj)) -- See which class the object was created from
>>> from twisted.internet import reactor
>>> print(type(reactor))
Core data type
The Numbers: int long, float complex, bool (0: False, 1: True)
Character: str unicode
List: list
Tuples: tuple
Dictionary: dict
File: file
Others: set (collection), frozeset, class type, None
The above is the data type of Python object introduced to you by this site. I hope it will be helpful to you. If you have any questions, please leave a message to me.