Basic data Types
In Python, there are several types of data that can be processed directly:
integer
Python can handle integers of any size, including negative integers, in which the notation in the program is the same as in mathematics, for example:6, -666
8888...
Computers use binary, so it is sometimes convenient to use hexadecimal notation for integers, and hexadecimal is 0x
represented by prefixes and 0-9,a-f, such as
>>> 0xaa6643622>>> 0xaf56dc11491036
floating point number
Floating-point numbers are decimals. Floating-point numbers can be used in mathematical notation, such as 0.681
-6.58……但
large or very small floating-point numbers, you must use the E notation (scientific notation), the 10 with e alternative, 3.5x109 is 3 .5e9。
Integers and floating-point numbers are stored inside the computer in different ways, integer operations are accurate, and floating-point arithmetic can have rounding errors.
Boolean value
A Boolean value of True
only False
two values, Boolean values can be used and
, or
and not
operations.
string
' let\ ' s go! ' " Let ' s go! "
An escape character \
can escape many characters, such as a \n
newline, a \t
tab, and the character \
itself, so \\
the character represented is\。
Print (' newline \ntab\t\\') wrap tab \
Python also allows r‘‘
the use ‘‘
of strings that represent internal literals that are not escaped by default.
Print (R' newline \ntab\t\\') line wrap \ntab\t\\
Python also allows a ‘‘‘...‘‘‘
format to represent multiple lines of content, simplifying a bunch of ' \ n ' and liking one.
>>> str=' ' spring-blown petals are not for the fruit of the future, but for a moment's hing. --Tagore "fireflies" ">>> str" spring blowing petals, \ n is not for the fruit of the future born, \ n Just for a moment's hing. \n--Tagore "Fireflies set"'print(str) Spring blowing petals, not for the future fruit, but for a moment of the hing. --Tagore's "Fireflies Collection"
Null value
A null value is a special value in Python, None
denoted by. None
cannot be understood as 0
, because 0
it is meaningful.
variables
Python variables do not need to be declared, you can enter directly:
Print (PY) Print (Type (py))<class'float'>
Then there's a variable py in your memory, with a value of 6.88, and its type is float (floating point). You don't need to make any special statements before, and data types are automatically determined by Python.
Here, we learned a built-in function type () that can query the type of the variable.
Constants
Constants are immutable variables, such as the commonly used number π, which is a constant. In Python, it is common to use all uppercase variable names to denote constants, Pi, and so on.
Discussion on division of Small
Python3. The division of integers in the X version differs from the 2.X version.
in 3.X ( True Division: Returns the true value regardless of the operand integer or float type:
>>> 5/22.5>>> 5.0/22.5>>> 5/2.02.5>>> 5.0/2.02.5
2.X ( Traditional Division ):
>>> 5/22>>> 5.0/22.5>>> 5/2.02.5>>> 5.0/2.02.5
from __future__ Import # Precision Division >>> 5/22.5
Python operator:
(1): Monocular operator: Plus (+), minus (-)
(2): Binocular operator: + 、-、 *,/,%, * *,//
About Floor Division (according to the Python version, Python versions <= 2.6, for traditional division: integers: Rounding out the fractional part, returning an integral type):
>>> 5//22
Summary of the day
Learn about Python's basic data types, constants, and variable concepts. The assignment of the variable, as well as the python2. The difference between division in X and 3.X.
Python③ Python Basic data types, variables, and constants