author:Once Day date:2022 year 2 month 16 Japan
The purpose of this document is to summarize the relevant contents , Scattered knowledge is difficult to remember and learn .
This document is based on windows platform .
View a full range of documents :python Basics _CSDN Blog .
Variable : While the program is running , The amount by which the value changes
Constant : While the program is running , A quantity whose value does not change
stay Python in , Variable is variable , It has no type , What we say " type " Is the type of object in memory that the variable refers to .
therefore Python Variables in do not need to declare types . Assignment creates a variable :
var_a=100
Variables should be assigned values before they are used , References to unassigned variables will appear NameError.
python Variable points to an object , This object has types and properties , Therefore, different types of values can be assigned to the same variable successively .Python Everything in is the object , Variables are references to objects !
>>> a=100
>>> a
100
>>>a='onceday'
>>>a
'onceday'
python There is no real constant , Some means are needed to simulate the use of . Follow up .
Python The numeric type is used to store numeric values . The value type is not allowed to be changed , If you change the value of the digital data type , Memory space will be reallocated .
Python Supports three different number types , Integers 、 Floating point and complex number :
Python3 The integer of can be regarded as Long type ( Longer integers )
When it comes to numbers , It can be expressed in octal or hexadecimal :
Hexadecimal use 0x The prefix and 0-9,a-f Express , for example :0xff00,0xa5b4c3d2.
Octal uses 0o The prefix and 0-7 Express , for example 0o12
Python A small integer object pool will be created automatically during initialization , Convenient to call , Avoid late duplicate generation ! The scope is -5~256 about , This is a common range .
Python There is an integer buffer , The integer just deleted , It won't be removed and recycled immediately , It's buffering in the background for a while , Waiting for the next possible call .
Conversion of data types , Just use the data type as the function name .
Be careful : Cast may lose precision .
Python The interpreter can be used as a simple calculator , You can enter an expression in the interpreter , It will output the value of the expression .
An expression is a normal mathematical expression , But there are a few things to note :
stay Python In language , Boolean type has only two values ,True And False.
for example 0、0.0、-0.0、 An empty string 、 An empty list 、 An empty tuple 、 An empty dictionary
, These are judged to be False. and -1、"False"
Judged to be True.
You can use bool
Function test .** Boolean types can be used and、or and not operation .** You can even perform four operations , here
True=1,False=0.
>>> True *3
3
>>> False -1
-1