Python basic data type Integer and Boolean

Source: Internet
Author: User

    • Integer and Boolean type
      • Gets the data type of the object
        • 1. Type ()
        • 2. Dir ()
        • 3. Help ()
        • 4, in the pycharm inside the operation
      • numeric type int
        • Create:
        • Int ()
          • Receive a numeric string
        • . Bit_lenght ()
        • Length of type int
      • Boolean type bool
Gets the data type of the object 1, type ()

to view the data type of an object
Example: (String)

1."abc"
2.print(type(s))

Results:

1.<class‘str‘>
2. Dir ()

View all the methods that the object's corresponding class has

1."hi"
2.bdir(temp)
3.print(b)
3. Help ()

View Help

1."hi"
2.help(type(temp)) #同样可以查看对应类和类的所有方法
4, in the pycharm inside the operation

Press CTRL and then directly click on the corresponding method –> can be directly located to the method

The number type int is created:

n = 123
Or
n = Int (123)

Attention:

  1. The results of the above 2 creation methods are the same, but in Python they are essentially different.
  2. The parameters that are passed into the integer type must be all numbers. Otherwise it will be an error!
  3. The transformation of an int () that essentially runs
  4. int conversion method inside the * __init__() * * method
Int ()

can receive 2 parameters

    • The first argument is a binary code or a numeric string
    • The second parameter is what type of input you want the result to be displayed in, and the runtime will display it according to the input system.
Receive a numeric string
1."123"
2.print(int(n))

Results:

1.123

Pass in the second argument

1.int("100", base = 2)
2.print(n)
3.int("100", base = 4)
4.print(n)

Results:

1.4
2.6

Note:
1. When you pass in a numeric string, you cannot pass the second argument
2. When the second parameter is passed in, the first argument must be in the format of a binary; 报错!
3, the second parameter can not write; default is decimal

. Bit_lenght ()

Gets the minimum number of digits that can be represented by the binary

1.4     #4二进制:00000100
2.ret = n1.bit_length()
3.print(ret)

Results:3

Length of type int

The length will vary depending on the range of the computer, and if the setting is out of range;

    • 32-bit system: -231-231-1
    • 64-bit system: -263-263-1

Attention:
There is no length limit after python3.0, as long as your memory is installed under. It can be infinitely large
.
Boolean type bool

true or False
1 or 0

Python basic data type Integer and Boolean

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.