[Python study notes] Python data types

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, Ospace , Kthese 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 \nline \tbreaks, 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 \nis 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 Trueand Falsetwo kinds of value.

Boolean values ​​can also be calculated, used and, orand operated not.

andThe operation is AND operation, only if all are True, the andoperation result is True.

orThe operation is OR operation, as long as one of them is True, the oroperation result is True.

notOperation is non-operation, it is a monocular operator, turns Trueinto False, Falsebecomes True.

Null value

Null value is a special value in Python, Noneexpressed by. NoneI can not understand is 0, because 0it makes sense, but Noneis a special null value.

variable

a = 1

aIs a variable

a = 'ABC'

As above, the Python interpreter does two things:

  1. Created a 'ABC'string in memory ;
  2. Created a avariable 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.

  1. One is /.
>>> 10 / 3
3.3333333333333335
  1. The other is //calledBaseplate.
>>> 10 // 3
3
Published 18 original articles · Likes6 · Visits 1859

Guess you like

Origin blog.csdn.net/qq_43479203/article/details/105093492