- 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 ()
- . 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:
- The results of the above 2 creation methods are the same, but in Python they are essentially different.
- The parameters that are passed into the integer type must be all numbers. Otherwise it will be an error!
- The transformation of an int () that essentially runs
- 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