Numeric (integer, floating point, Boolean), floating point Boolean
I. Integer:
1)Integer(Int )-It is usually called an integer or integer. It is a positive or negative integer without a decimal point.
Python3 has no size limit and can be used as the Long type. Therefore, Python3 does not have the Long type of Python2.
For example:
Num01= 10000
Num02= 10000000000000000000000000000000000000000
Num03 = 0x123456#Hexadecimal
Num04 = 0o1234567#Octal
Num05 = 1e20#Scientific notation
Print ("Num01 :", Num01, type (num01 ))
Print ("Num02 :", Num02, type (num02 ))
Print ("Num03 :", Num03, type (num03 ))
Print ("Num04 :", Num04, type (num04 ))
Print ("Num05 :", Num05, type (num05 ))
Num01 02 03 04 are all Integers
2) How can I check how much space a variable occupies?
For example:
ImportSys
Print ("Num01Occupied Space", Sys. getsizeof (num01 ))
Print ("Num02Occupied Space", Sys. getsizeof (num02 ))
3) Common integer methods:
#Demo:
ImportMath
If_ Name __= ="_ Main __":
Print (abs (108 ))
Print (abs (-1, 100 ))
Print (math. fabs (-100 ))
Print (math.sqrt (100 ))
# Print (math. sqrt (-100 ))
Print (math. pow (3, 4 ))
Print (max (12, 34, 67, 45,106, 45 ))
Print (min (12, 34, 67, 45,106, 45 ))
Ii. Floating Point
Num01= 0.00000000000000000000000000123
Num02= 1000000000000000000000000000.11
Print (num01)
Print (num02)
Display:
1.23e-11
1e + 27
FloatPrecision is17Bit, exceeds17BITs are represented by scientific notation
1) In the floating pointRound
Number of digits after the decimal point, which is often used
Num01= 12.3456789123456789
Print (round (num01) # Get the entire number
# Retain decimal places. round returns the rounded decimal places.
Print (round (num01, 2 ))
Print (round (num01, 3 ))
Print (round (num01, 4 ))
Print (round (12.35, 1) # returns 12.3
It is not a standard rounding rule. We will not talk about it first.
2) Ceil in floating point
ImportMath
If_ Name __= = "_ main __":
Num01= 12.3456789123456789
Print (math. ceil (num01 ))
Print (math. ceil (-12.1111111 ))
CeilReturns the upper integer of a number. The positive and negative numbers are different.
3) Floor returns the rounded down integer of the number.
Print (math. floor (num01 ))
Print (math. floor (-12.1111111 ))
4) Modf returns the integer and decimal part of X. The values of the two parts are the same as those of X, and the integer part is expressed as a floating point.
Print (math. modf (num01 ))
Print (math. modf (-12.12345678 ))
Returns, but the value is not very accurate:
(0.3456789123456794, 12.0)
(-0.12345677999999971,-12.0)
Iii. boolean type:False TrueCan participate in mathematical operations
Is_small =True# The storage is 1.
Is_first =False# The storage is 0.
Print (is_small + 100)
Print (is_first * 100)
Return Value:
101
0
All integers other than 0 are true, and 0 is False.
If0:
Print ("true ")
Else:
Print ("false ")