Python Data type Notes

Source: Internet
Author: User

the types of data that can be processed directly in Python can be divided into integers, floating-point numbers, strings, booleans, and null values.

The size of integers and floating-point numbers represented in Python is arbitrary and does not have a limit on the range represented by each data type, as in other high-level languages such as Java, which is also python One of the reasons why it is simple and convenient to use.

For integer and floating-point arithmetic,python provides +(plus),-(binocular minus, single-eye negative),*(multiply) ,/(except),%(modulo),* *(Power),//(divisible)

The difference between the divide and take is as follows:

9/2 = = 4 9//2 = = 4

9.0/2 = = 4.5 9.0//2==4.0

As can be seen from the above example, "/" if the divisor or divisor has a floating-pointnumber,"/" result is a decimal, and "// " operator in the case of a divisor or divisor with a floating-point number, the result is a floating-point number that divides the result plus a fractional part of 0.

Pythonthe string in is in single quotation marks(')or double quotes(")any text enclosed, you can use the escape character inside the string(\), the usual escape characters are\ ',\",\ n,\ t,\\....and so on. If you do not want to use escape characters in your string, you can also choose to use ther "string"the form of the escape character is canceled\The role in the string.

python and java and and or and not operation.

where and and or operations are short-circuit evaluated, the following example illustrates the problem:

Execute under the Python command line interface:


Traceback (most recent):

File "<stdin>", line 1, in <module>

Nameerror:name ' false ' is not defined

and execution

>>> True or False


Indicates that the or operation returns a true value when the first operand is true , and Operator returns false when the first operand returns false .

NULL, A special value in Python, denoted by None (for later use).

The variables in Python do not need to be type-declared before they are used, which is similar to Perl and inconsistent with the Java language. It is convenient to assign numbers or strings and objects directly to a named variable when used.

Like what:

A = 10

A = 10.0

A = "string"

Python also provides other more useful data types, such as lists, dictionaries, and custom types, and continues to take notes later.

Python Data type Notes

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: 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.