Python It is allowed to assign values to multiple variables at the same time , for example :
a = b = c = 1
Create an integer object , The value is 1, From the back to the front , Multiple variables are given the same value
Python There are six standard data types in :
Python Of the six standard data types :
number
( Numbers )、string
( character string )、tuple
( Tuples )list
( list )、dictionary
( Dictionaries )、set
( aggregate )(1).int
integer :Python Can handle integers of any size .
(2).flolat
floating-point : It is composed of integral part and decimal part , To approximate or round without being able to calculate accurately .
(3)bool
Boolean type : Used as a logical judgment , The value of a variable is only true (True) And fake (False),
(4)complex
The plural : It is composed of a real number and an imaginary number , Expressed as :x+yj
, A complex number is a pair of ordered floating-point numbers (x,y), among x Is the real part , Is the imaginary part .
We can convert numeric types through built-in functions .
int
Convert to bool
,0 convert to False, Not 0 convert to True.print(bool(a))# a For integer numbers
bool
Convert to int
,False convert to 0,True convert to 1.print(int(a))# a by False or True
float
Convert to int
print(int(a))# a Is a floating-point number
int
Convert to float
print(float(a))# a For integer numbers
bool
Convert to float
print(float(a))# a by False or True
float
Convert to bool
print(bool(a))# a Is a floating-point number
hex(i)
take 10 Hexadecimal numbers are converted to 16 Base number .oct(i)
take 10 Hexadecimal numbers are converted to 8 Base number .bin(i)
take 10 Hexadecimal numbers are converted to 2 Base number .Be careful : Switching , If there are other useless characters, an error will be reported , Plus and minus signs make sense .
'
And double quotes "
Cover up , Also use a backslash \
Escapes special characters .+
Is the concatenator of a string ,*
Means to copy the current string , The number that follows is the number of copies .[]
Between , A comma separated list of elements .+
Is a list connector *
Is a repeat operation , The elements in the list can be changed . Tuples are similar to lists , The difference is that elements of tuples cannot be modified , Tuples are written in parentheses ()
in , Use commas... Between elements ,
separate .
Tuples are similar to strings , Can be indexed and indexed from 0 Start ,-1 Is the beginning of the end . Although tuples are immutable , But it can contain mutable objects . Tuples also use +
To splice .
Be careful :string
,list
,tuple
All belong to sequebce
( Sequence ) Of .