table of Contents
Integer and floating point types are collectively referred to as digital
A. Integer built-in method (int)
1. Use
Age, number, rank description
2. Definitions
You may be used int () method to convert a pure numeric characters to decimal integer
age = 19 #age = int(19)
print(type(age))
#<class 'int'>
a = int('111')
print(type(a))
#<class 'int'>
x = int('11.1') # 报错
print(x)
3. The method of common operations built +
Arithmetic comparison operation +
- Long integer
Long integer exists only in python2, there is no long integer in python3
x = 11111111111111111111111111111111111111111111111
print(type(x)) # longint
4. The presence of a plurality of values or value
A value
5. orderly or disorderly
No one said an orderly or disorderly
6. The variable or invariable
ID immutable values, i.e., modified on the basis of the original value, for the variable data type; variable ID value becomes, i.e., to re-apply a new value into the space, compared with the data type immutable
age = 19
print(f'first:{id(age)}')
age = 20
print(f'second:{id(age)}')
#first:4384901776
#second:4384901808
II. Float built-in method (float)
1. Use
Payroll description, height, and weight data
2. Definitions
You can float () method of the string to a purely digital floating-point number
age = 3.1 # age = float(3.1)
print(type(age))
#<class 'float'>
x = float('111')
print(x)
print(type(x))
#111.0
#<class 'float'>
x = float('11.1') # 报错
print(type(x))
#<class 'float'>
3. The method of common operations built +
Arithmetic comparison operations +
4. The stored value or a plurality of values
A value
5. orderly or disorderly
No one said an orderly or disorderly
salary = 3.1
print(f'first:{id(salary)}')
salary = 5.1
print(f'second:{id(salary)}')
#first:4423173584
#second:4423173800
6. The variable or invariable
Immutable data type