Python data type

Source: Internet
Author: User

1.1   Data Type1.1.1   integer

Python can handle integers of any size, including, of course, negative integers, which are represented in the program in the same way as mathematically, for example:1,-8080, 0, and so on.

computer because of the use of binary, so, sometimes hexadecimal notation is more convenient, hexadecimal with 0x prefix and 0-9,a-f, such as:0xff00, 0xa5b4c3d2, wait.

1.1.2   floating point number

floating-point numbers, which are decimals, are called floating-point numbers because, when represented by scientific notation, the decimal position of a floating-point number is variable, for example,1.23x109 and 12.3x108 are exactly equal. Floating-point numbers can be mathematically written, such as 1.23,3.14,-9.01, and so on. But for very large or very small floating-point numbers, it must be expressed in scientific notation, the use of e instead,1.23x109 is 1.23e9, or 12.3e8,0.000012 can be written in 1.2e-5, and so on.

1.1.3   string

The string is in single quotation marks 'or double quotation marks"Enclosed.of any text, such as' ABC ',"XYZ"and so on. Please note that‘‘or""itself is just a representation, not part of a string, so the string' ABC 'onlyA,B,Cit3a character. If‘itself is also a character, it can be used""Including , for example,"I ' m OK"contains the characters that areI,‘,M, spaces,O,Kit6a character.

What if the inside of a string contains both ' and contains ' ? You can use the escape character \ to identify

>>> print (' i\ ' m a\ "boy\")

I ' m a "boy"

escape character \ can escape many characters, such as \ n for line break ,\ t for tab , character \ itself to be escaped, so the character \ \

If there are many characters in the string that need to be escaped, you need to add a lot of \, in order to simplify,Python also allows to use r " ' The internal string is not escaped by default

>>> print (R ' \\\\\t ')

\\\\\t

If there is a lot of line wrapping inside the string, it is not good to read it in a line, in order to simplify,Python allows the "... " format to represent multiple lines of content

>>> print (' L1 # ' in interactive Python followed by the ENTER key, three points at the beginning of the downlink

... L2

... L3 ")

L1

L2

L3

Note that you write directly to the command script

[email protected] python]# cat!$

Cat./mult_line.py

#!/usr/bin/python

Print ("' L1

L2

L3

End ")

[Email protected] python]#./mult_line.py

L1

L2

L3

End

1.1.4   Boolean value

A Boolean value is exactly the same as that of a Boolean algebra, and A Boolean value is only True , False two kinds of values , or is True, or false, in Python, theboolean value (note case) can be expressed directly with True and false. It can also be computed by Boolean operations.

>>> true

Traceback (most recent):

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

Nameerror:name ' true ' is not defined

>>> True

True

>>> False

False

>>> 3>2

True

>>>

Boolean expressions support and,or, not operations, and do not make too many statements.

>>> True and False

False

>>> True or False

True

>>> not False

True

1.1.5   Null value

A null value is a special value in Python that is similar to NULL in SQL .

1.1.6   variables

>>> a=1

>>> Print (a)

1

>>> a= ' 780 '

>>> Print (a)

780

>>> a= ' TZ780 '

>>> Print (a)

TZ780

>>> A=true

>>> Print (a)

True

in the in Python, the equal sign = is an assignment statement, you can assign any data type to a variable, the same variable can be repeatedly assigned, and can be a different type of variable, is a dynamic variable, variable type is indeterminate.

Note the transfer between variables

>>> a= ' abc '

>>> B=a

>>> a= ' xyz '

>>> print (b)

Abc

1.1.7   Constants

in the in Python, constants are usually represented in all uppercase variable names , and for canonical notation, as in the case of all uppercase variables in the shell.

Finally, explain why the division of integers is also accurate. In Python , there are two types of division, one division is /:

>>> 10/3

3.3333333333333335

/ division evaluates to a floating-point number, even if two integers are evenly divisible, the result is a floating-point number:

>>> 9/3

3.0

There is also a division is //, called the floor except, the division of two integers is still an integer:

>>> 10//3

3

you are not mistaken, the whole number of floors except // is always an integer, even if not endless. To do the exact division, use / can.

because // division takes only the integer part of the result, Python also provides a remainder operation that gives the remainder of dividing two integers:

>>> 3

1

The result is always an integer, regardless of whether the integer is done // division or the remainder, so the result of the integer operation is always accurate.

Python has no size limit for integers

Python has no size limit for floating-point numbers


This article is from the "90SirDB" blog, be sure to keep this source http://90sirdb.blog.51cto.com/8713279/1795429

Python data type

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.