A detailed introduction to data types in Python objects

黄舟
Release: 2017-05-14 11:26:52
Original
1367 people have browsed it

For python, everything is object, all data stored in the program are objects, and objects are created based on classes. This article mainly introduces the data 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.

class refers 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 of others Reference 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))
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!