Python object data type, python Data Type

Source: Internet
Author: User
Tags floor division

Python object data type, python Data Type

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 a variety of data, such as text, graphics, audio, video, and web pages. Different data types need to be defined.
Class refers to the custom type, and type refers to the built-in type. Both of them indicate different data types.

Each object has an identity, a type, and a value. The identity refers to the pointer of the object in memory (the address in memory), and the built-in function id () returns the identity of an object. The variable name is the name that references the specific location.
Instantiate: create 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 variable object.
If the object value cannot be modified, it is called an immutable object.
Container: an object contains references to other objects, such as a 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, all the functions in the object are found in the class.
Most objects have a large number of unique data attributes and methods.
Attribute: The value related to the object, such as the variable name.
Method: functions that perform certain operations on objects when called

Python will make the operations frequently used in the type
1. built-in Methods
2. Syntax sugar, automatic touch Method


>>> Name = 'test'
>>> Name. upper () -- Method
TEST
>>> Num = 1
>>> Print (num. real) -- attribute
1

Help (type) -- view the methods or attributes of a type
>>> Help (int)
Help (type. func) -- find the usage of a Method
>>> Help (str. find)
You can use the dot (.) operator to access attributes and methods.
Print (type (obj) -- view which class of the object is created
>>> From twisted. internet import reactor
>>> Print (type (reactor ))

 

Core Data Type
Number: int, long, float, complex, bool (0: False, 1: True)
Character: str, unicode
List: list
Tuples: tuple
Dictionary: dict
File: file
Others: set, frozeset, class type, None

A null value is a special value in Python, expressed as None. None cannot be understood as 0, because 0 is meaningful, and None is a special null value.


Python object operations

1. Arithmetic Operations
+-*/% // ** =! ===
+ =-= * =/= % = // = ** =

// The floor division is an integer.
**: Power
%: Modulo, I .e., remainder

>>> (1 + 0.01) ** 365 -- make a little progress every day
37.78343433288728
>>> (1-0.01) ** 365 -- regressing every day
0.025517964452291125

Python has a value-related library math. The math module can implement advanced arithmetic operations.
>>> Import math
>>> Math. pi
3.141592653589793

2. bitwise operation: When bitwise operations are performed, the number is treated as binary.
& Bitwise AND, both of which are true results are true
| Bitwise OR, as long as one real result is true
^ Returns an exclusive bitwise OR. Only true and false returns true.
~ Bitwise inversion, >>> ~ 9 =>-10
<Move left: shifts the bit to the left.
> Move right: shifts the bit to the right.
 

128 64 32 16 8 4 2 0
0 0 0 0 0 0 0
10 1 0 1 0
50 1 1 0 0 1 0
& 0 0 0 0 1 0
| 1 1 1 0 1 0


3. logical operators
And
Or
Not

In Python, True and False can be used to represent boolean values (case-sensitive) or computed using Boolean operations. Boolean values can be calculated using and, or, and not.
And operations are and operations. Only True is used for all operations, and True is used for all operations;
Or is an or operation. If either of them is True, or is True;
The not operation is not an operation. It is a single-object operator that converts True to False and False to True.
Boolean values are often used in condition judgment, for example:
If age> = 18:
Print ('adresult ')
Else:
Print ('teenager ')


4. member operators
In
Not in


5. Identity Operators
Is
Is not



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.