type of data
Integer
任意大小
Integers that Python can handle .
Floating point (decimal)
Integers and floating-point numbers are stored differently inside the computer. Integer operations are always accurate, and floating-point operations may have rounding errors.
String
A string is single quotes '
or double quotes "
any text enclosed.
"I'm OK"
It contains the character I
, '
, m
, O
space , K
these 6 characters.
Escape character
What if the string is both contained '
and contained "
? Can \
be identified with escape characters ,
'I\'m \"people\"!'
as follows:
I'm "people"!
Escape characters \
can escape many characters, such as \n
line \t
breaks, tabs, and the characters \
themselves must be escaped, so \\
the characters represented are \
.
If there are many characters need to be escaped, it may be necessary to use a lot \
, for simplicity, you can use r''
represent ''
the string inside the default does not escape.
>>> print('\\\t\\')
\ \
>>> print(r'\\\t\\')
\\\t\\
If there are many newlines inside the string, it \n
is not easy to read in one line. For simplicity, you can use '''...'''
the format to represent multiple lines of content.
>>> print('''line1
... line2
... line3''')
line1
line2
line3
...
This is not part of the code, it appears after typing the previous line and then hitting Enter Prompt Prompts you to type the next line.
Boolean value
Boolean value only True
and False
two kinds of value.
Boolean values can also be calculated, used and
, or
and operated not
.
and
The operation is AND operation, only if all are True
, the and
operation result is True
.
or
The operation is OR operation, as long as one of them is True
, the or
operation result is True
.
not
Operation is non-operation, it is a monocular operator, turns True
into False
, False
becomes True
.
Null value
Null value is a special value in Python, None
expressed by. None
I can not understand is 0
, because 0
it makes sense, but None
is a special null value.
variable
a = 1
a
Is a variable
a = 'ABC'
As above, the Python interpreter does two things:
- Created a
'ABC'
string in memory ; - Created a
a
variable named in memory and pointed it'ABC'
.
constant
Variables that can not change, like π
that is a constant.
Precise interpretation of division
There are two kinds of division in python.
- One is
/
.
>>> 10 / 3
3.3333333333333335
- The other is
//
calledBaseplate.
>>> 10 // 3
3