python basis - numeric type built-in method

Python3 There are six standard data types:
Number The (digital)
String (String)
List (list)
Tuple (tuple)
the Set (set)
the Dictionary (dictionary)
six Python3 of standard data types:
immutable data (3 a): number (number), string (string), tuple (tuple);
variable data (3): list (lists), Dictionary (dictionary), set (set)

Integer and floating-point digital collectively referred to as type.

Integer built-in method (int)

  • 1. Purpose: age, number, rank
  • 2. Definitions: use int (), the purely digital string to decimal integer
age = 19  # age = int(10)
print(type(age))

<class 'int'>

x = int('111')
print(type(x))

<class 'int'>

x = int('11.1')  # 报错
print(x)
  • 3. Method built + common operations: arithmetic comparison operations +
    ** 1.0.1 ** Long
    Long exists only in python2, python3 does not exist in a long integer.

x = 11111111111111111111111111111111111111111111111
print(type(x)) # longint

  • 4. The stored value or a plurality of values: a value

  • 5. orderly or disorderly: no orderly or disorderly say

age = 19
print(f'first:{id(age)}')
age = 20
print(f'second:{id(age)}')

first:4384901776
second:4384901808

  • 6. The variable or non-variable: immutable data types.


Built-float method (float)

  • 1. Use: payroll, height, weight
  • 2. Definitions: 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. Method built + common operations: arithmetic comparison operations +

  • 4. The stored value or a plurality of values: a value

  • 5. orderly or disorderly: no orderly or disorderly say
salary = 3.1
print(f'first:{id(salary)}')
salary = 5.1
print(f'second:{id(salary)}')

first:4423173584
second:4423173800

  • 6. The variable or non-variable: immutable data type

Variable or immutable

id constant value of the variable, i.e., modified on the basis of the original value, for the variable data type; id value becomes variable, i.e., to re-apply a new value into the space, compared with immutable data types.

Guess you like

Origin www.cnblogs.com/suren-apan/p/11374819.html