Python3 base integer commonly used methods, python3 base integer

Source: Internet
Author: User

Python3 base integer commonly used methods, python3 base integer

It is hoped that it will be of reference value for everyone to learn or use python3.

 

_ Abs _ # returns the absolute value of a number.

>>> Num3 =-22

>>> Num3. _ abs __()

22

_ Add _ # add two numbers

_ And _ # bitwise and operation of two numbers

_ Bool _ # Boolean Value of a number

>>> Num1 = 4

>>> Num1. _ bool __()

True

_ Delattr _ # placeholder

_ Ceil _ # placeholder, return itself

_ Dir _ # placeholder

_ Divmod _ # Division to obtain the tuples consisting of the quotient and remainder

>>> Num4 = 18

>>> Num4. _ divmod _ (7)

(2, 4)

_ Doc _ # document for retrieving Integers

_ Eq _ # determine whether the two numbers are equal. If they are equal, True is returned. If they are not equal, False is returned.

_ Float _ # convert to the floating point type

>>> Num5 = 6

>>> Num5. _ float __()

6.0

_ Floor _ # placeholder

_ Floordiv _ # Calculate the remainder of the division of two numbers

>>> Num6 = 42

>>> Num6. _ floordiv _ (5)

2

_ Format _ # placeholder

_ Ge _ # judge whether the previous number is greater than or equal to the parameter, and return a Boolean Value

_ Getattribute _ # placeholder

_ Getnewargs _ # placeholder

_ Gt _ # determine whether the previous number is greater than its parameter and return a Boolean Value

_ Hash _ # placeholder

_ Index _ # placeholder

_ Init __#IntClass Constructor

_ Int _ # convert a number to an integer

_ Invert _ # bitwise inversion of binary data

_ Le _ # determine whether a number is equal to or less

_ Lshift _ # convert a decimal number into a binary number and then shift it to the left

>>> Num5 = 6 # convert 6 in decimal format to 2 in decimal format of 110, and offset 2 to the left is 11000.

>>> Num5. _ lshift _ (2) # convert to a decimal value of 24.

24

_ Lt _ # determine whether a number is smaller than the Parameter

_ Mod _ # return the remainder of division of two numbers

>>> Num1 = 18

>>> Num1. _ mod _ (4)

2

_ Mul _ # multiply two numbers

>>> Num1 = 4

>>> Num1. _ mul _ (3)

12

_ Ne _ # judge whether two numbers are not equal. A boolean value is returned.

_ Neg _ # returns the inverse value. A positive number is converted to a negative number, and a negative number is converted to a positive number.

>>> Num1 = 4

>>> Num1. _ neg __()

-4

_ New _ # placeholder

_ Or _ # bitwise or operation of two numbers

_ Pos _ # placeholder

_ Pow _ # power, that is, the 3rd power of 4

>>> Num1 = 4

>>> Num1. _ pow _ (3)

64

_ Radd _ # change the positions left and right, and then add the two numbers.

_ Rand _ # change the positions left and right, and then calculate the two numbers

_ Rdivmod _ # change the positions left and right, and then calculate the parameter and the quotient and remainder of the parameter.

_ Reduce _ # placeholder

_ Performance_ex _ # placeholder

_ Repr _ # Return itself

_ Rfloordiv _ # evaluate the quotient between the parameter and itself, and take the integer part

>>> Num1 = 6

>>> Num1. _ rfloordiv _ (45)

7

_ Rlshift _ # binary left shift operation. 2 is represented as 10 in binary format, and 4 bits are shifted to the left, that is

>>> Num1 = 6 #100000, which is converted into a decimal value of 32 and shifted to the left by 5 digits.

>>> Num1. _ rlshift _ (2) #1000000. Convert the value to 64 in decimal format.

128

>>> Num1 = 4

>>> Num1. _ rlshift _ (2)

32

>>> Num1 = 5

>>> Num1. _ rlshift _ (2)

64

_ Rmod _ # Calculate the remainder of the parameter and its division

>>> Num1 = 6

>>> Num1. _ rmod _ (45)

3

_ Rmul _ # product for multiplying a parameter and itself

>>> Num1 = 6

>>> Num1. _ rmul _ (45)

270

_ Ror _ # bitwise OR operation of two numbers

_ Round _ # placeholder

_ Rpow _ # power N of the operation parameter, that is, power 5 of 3

>>> Num1 = 5

>>> Num1. _ rpow _ (3)

243

_ Rrshift _ # convert 32 in decimal number to 100000 in binary format, and offset to the right is

>>> Num1 = 2 #1000, which is 8 after being converted to decimal.

>>> Num1. _ rrshift _ (32)

8

_ Rshift _ # convert a decimal number to binary, and then offset to the right

>>> Num7 = 26 # convert the decimal value 26 to the binary value 11010, And the offset to the right is 110.

>>> Num7. _ rshift _ (2) # convert to 6 in decimal format.

6

_ Rsub _ # subtraction of parameters

>>> Num = 4

>>> Num. _ rsub _ (3)

-1

_ Rtruediv _ # parameter division

>>> Num = 4

>>> Num. _ rtruediv _ (3)

0.75

_ Rxor _ # bitwise OR operation between the parameter and itself, 4 is converted to binary, and 7 is converted

>>> Num = 4 # convert the binary value to 111. After bitwise OR calculation, the return value is 011 and the return value is converted to binary.

>>> Num. _ rxor _ (7) # The hexadecimal value is 3.

3

_ Setattr _ # placeholder

_ Sizeof _ # placeholder (I don't know how to use it)

>>> Num = 16

>>> Num. _ sizeof __()

28

>>> Num = 4

>>> Num. _ sizeof __()

28

>>> Num = 222

>>> Num. _ sizeof __()

28

>>> Num = 233333

>>> Num. _ sizeof __()

28

_ Str _ # convert to a string

_ Sub _ # subtraction of two numbers

>>> Num = 16

>>> Num. _ sub _ (9)

7

_ Subclasshook _ # placeholder

_ Truediv _ # division of two numbers

>>> Num = 16

>>> Num. _ truediv _ (5)

3.2

_ Trunc _ # placeholder (I don't know how to use it)

>>> Num = 6

>>> Num. _ trunc __()

6

>>> Num = 8

>>> Num. _ trunc __()

8

_ Xor _ # bitwise xor operation

Bit_length # returns the minimum number of digits occupied by this number.

>>> Num1 = 33

>>> Num1.bit _ length () # indicates that the binary value is 00100001 in decimal 33, and the minimum bit is 100001.

6

Conjugate # Return the combination of the Complex Numbers

>>> Num2 = 3 + 4j

>>> Num2.conjugate ()

(3-4j)

Denominator # placeholder

From_bytes # placeholder

Imag # placeholder

Numerator # placeholder

Real # placeholder

To_bytes # placeholder

 

Related Article

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.