How to use int integral type in Python3

Source: Internet
Author: User
This article mainly introduces the use of Int (integer) in the Python3 tutorial, the article introduced in very detailed, I believe that you learn or use Python3 can have a certain reference value, the need for friends below to see it together.

The PYTHON3 supports three different numeric types:

    1. Integer (int)--often referred to as an integral or integer, can be a positive or negative integer, without a decimal. Python3 integers are not limited in size and can be used as long, but in fact, because of limited machine memory, the integer we use is not infinitely large.

    2. Float (float)--floating-point numbers consist of integral and fractional parts, and floating-point types can also be represented using scientific notation (2.5e2 = 2.5 x 102 = 250)

    3. Complex numbers (complex)-complex numbers are made up of real and imaginary parts, and can be represented by a + BJ, or complex (a, b), where both the real and imaginary part of a complex number are floating-point.

Let's take a look at the detailed introduction to int (integer type) in Python3.

__ABS__ (return absolute value)

n = -5print (n.__abs__ ()) #输出: 5

__add__ (Add, Operator: +)

n = 3print (n.__add__ (5)) #输出: 8

__AND__ (bitwise AND operation, operator:&)

n = 5print (n.__and__ (7)) #输出: AA 00000110# and Operation  # 00000111# equals 00000110

__bool__

#占位

__ceil__ (return to itself)

n = 1234print (n.__ceil__ ()) #输出: 1234

__PMOD__ (return divisor and remainder)

n = 13print (n.__pmod__ (5)) #输出: (2, 3)

__EQ__ (determine whether two numbers are equal, operator: = =)

n = 5print (n.__eq__ (3)) #输出: False

__FLOAT__ (Convert to floating-point type)

n = 5print (n.__float__ ()) #输出: 5.0

__floorp__ (divisible, returns the integer part of the quotient, Operator://)

n = 9print (n.__floorp__ (4)) #输出: 2

__floor__

#占位

__format__

#占位

__getattribute__

#占位

__getnewargs__

#占位

__GE__ (Judging whether >=)

n = 5print (n.__ge__ (3)) #输出: True

__GT__ (Judging whether >)

n = 5print (n.__gt__ (3)) #输出: True

__hash__

#占位

__index__

#占位

__invert__ (binary bitwise inverse, operator: ~)

n = 11print (n.__invert__ ()) #输出: -12#ps: Binary Negative representation method: Positive bitwise negation plus 1

__LE__ (Judging whether <=)

n = 5print (n.__le__ (3)) #输出: False

__lshift__ (binary left shift operation, operator:<<)

n = 12print (n.__lshift__ (2)) #输出: 48#ps: Binary left shift 1 bit equals decimal multiply 2, right shift one equals decimal except 2

__LT__ (Judging whether <)

n = 5print (n.__lt__ (3)) # #输出: False

__mod__ (modulo-returns the remainder of the division, Operator:%)

n = 14print (n.__mod__ (3)) #输出: 2

__mul__ (Multiply, operator: *)

n = 3print (n.__mul__ (6)) #输出: 18

__neg__ (inverse, positive to negative, negative to positive, operator:-)

n = 5print (n.__neg__ ()) #输出: 5

__new__

#占位

__NE__ (determines whether two values are not equal, operator:! =)

n = 5print (n.__ne__ (3)) #输出: True

__OR__ (bitwise OR operation, Operator: |)

n = 3print (n.__or__ (5)) #输出: 7# # 00000011# #或 # # 00000110# # 00000111

__pos__

# "" "+self" "" (don't know what it means)

__POW__ (returns the value of XY [x's Y-square])

n = 2print (n.__pow__ (3)) #输出: 8

__radd__ (Add, Operator: +)

n = 5print (n.__radd__ (3)) #输出: 8

__rand__

# "" "Return value&self. """

__rpmod__

# "" "Return pmod (value, self). """

__REPR__ (return to itself)

# "" "Return repr (self). """

__rfloorp__ (divisible, returns the integer part of the quotient, Operator://)

# "" "Return value//self. """

__rlshift__ (binary left shift operation, operator:<<)

# "" "Return value<<self. """

__rmod__ (modulo-returns the remainder of the division, Operator:%)

# "" "Return value%self. """

__rmul__ (Multiply, operator: *)

# "" "Return value*self. """

__ror__

# "" "Return value|self. """

__round__

#占位

__RPOW__ (returns the value of Yx [Y's X-square])

n = 3print (n.__rpow__ (2)) #输出: 8

__rrshift__

# "" "Return value>>self. """

__rshift__

# "" "Return self>>value. """

__rsub__

# "" "Return value-self. """

__rtruep__

# "" "Return value/self. """

__rxor__

# "" "Return value^self. """

__sizeof__

# "" "Returns size in memory, in bytes" ""

__str__

# "" "Return str (self). """

Sub (subtract)

# "" "Return self-value. """

__truep__ (Divide)

# "" "Return self/value. """

__trunc__

#占位

__XOR__ (Bitwise XOR, Operator: ^)

# "" "Return self^value. """

Bit_length (returns the minimum length of the binary)

>>> bin (PNS) ' 0b100101 ' >>> (PNS). Bit_length () 6

Conjugate

#占位

From_bytes

#占位

To_bytes

#占位
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.