Number in the Python3

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.