Number numeric type support: Int (integer) float (float) bool (Boolean) complex (plural)
The built-in type () identifies the type of object that the variable refers to:
A, B, c, d = Ten, 55.4, false, 4+3j
Print (Type (a), type (b), type (c), type (d))
# The result of the output is: <class ' int '> <class ' float '> < Class ' bool '> <class ' complex '>
< Span class= "pun" >< Span class= "pun" >< Span class= "pun" > You can also use the isinstance to determine:
< Span class= "pun" >< Span class= "pun" >< Span class= "pun" > A = 20.3
< Span class= "pun" >< Span class= "pun" >< Span class= "pun" > Print ( isinstance (A, float) )
< Span class= "pun" >< Span class= "pun" >< Span class= "pun" > # The output is ture
The difference between type and isinstance is:
- Type () does not consider a subclass to be a parent class type.
- Isinstance () considers a subclass to be a parent class type
In 2 there is no bool type, with 1 for true,0 representative false! And in 3, true and false are defined as keywords, and the values can be calculated as well as numbers.
Number in the Python3