Tutorial on the use of int (integer) in python3
- 2020-05-27 06:16:01
- OfStack
Python3 supports three different numeric types:
Let's take a closer look at int (integer) in python3.
S 24en__ (return the absolute value)
n = -5
print(n.__abs__())
# Output: 5
S 28en__ (add, operator: +)
n = 3
print(n.__add__(5))
# Output: 8
S 32en__ (by bit and operation, operator: & )
n = 5
print(n.__and__(7))
# Output: 5
# 00000110
# With the operation
# 00000111
# Is equal to the 00000110
__bool__
# placeholder
S 41en__ (return to itself)
n = 1234
print(n.__ceil__())
# Output: 1234
S 45en__ (return divisor and remainder)
n = 13
print(n.__divmod__(5))
# Output: (2, 3)
S 49en__ (judge if two Numbers are equal, operator: ==)
n = 5
print(n.__eq__(3))
# Output: False
S 53en__ (convert to floating point type)
n = 5
print(n.__float__())
# Output: 5.0
S 57en__ (take the integral part of the quotient, return, operator: //)
n = 9
print(n.__floordiv__(4))
# Output: 2
__floor__
# placeholder
__format__
n = 3
print(n.__add__(5))
# Output: 8
0
__getattribute__
# placeholder
__getnewargs__
# placeholder
S 77en__ (judge whether or not > =)
n = 3
print(n.__add__(5))
# Output: 8
3
S 83en__ (judge whether > )
n = 3
print(n.__add__(5))
# Output: 8
4
__hash__
n = 3
print(n.__add__(5))
# Output: 8
5
__index__
n = 3
print(n.__add__(5))
# Output: 8
6
S = s = s = s = s = s = s = s = s = s = s = s
n = 3
print(n.__add__(5))
# Output: 8
7
S judge whether/whether < =)
n = 3
print(n.__add__(5))
# Output: 8
8
S 106en__ (2 base left shift operation, operator: < < )
n = 3
print(n.__add__(5))
# Output: 8
9
S judge whether/whether < )
n = 5
print(n.__lt__(3))
# # Output: False
S 119en__ (modulus - return remainder of division, operator: %)
n = 14
print(n.__mod__(3))
# Output: 2
S 123en__ (multiply, operator: *)
n = 3
print(n.__mul__(6))
# Output: 18
S = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
n = 5
print(n.__neg__())
# Output: -5
__new__
# placeholder
S 135en__ (judge if the two values are not equal, operator:! =)
n = 5
print(n.__ne__(3))
# Output: True
S 139en__ (by bit or operation, operator: |)
n = 5
print(n.__and__(7))
# Output: 5
# 00000110
# With the operation
# 00000111
# Is equal to the 00000110
6
__pos__
n = 5
print(n.__and__(7))
# Output: 5
# 00000110
# With the operation
# 00000111
# Is equal to the 00000110
7
S 147en__ (return xy [x to y])
n = 5
print(n.__and__(7))
# Output: 5
# 00000110
# With the operation
# 00000111
# Is equal to the 00000110
8
S 154en__ (add, operator: +)
n = 5
print(n.__and__(7))
# Output: 5
# 00000110
# With the operation
# 00000111
# Is equal to the 00000110
9
__rand__
#""" Return value&self. """
__rdivmod__
# placeholder
1
S 166en__ (return to itself)
# placeholder
2
S 170en__ (take the integral part of the quotient, return the quotient, operator: //)
# placeholder
3
S 174en__ (2 base left shift operation, operator: < < )
# placeholder
4
S 181en__ (modulus - return remainder of division, operator: %)
# placeholder
5
S 185en__ (multiply, operator: *)
# placeholder
6
__ror__
# placeholder
7
__round__
# placeholder
8
S 197en__ (return the value of yx [y to x])
n = 3
print(n.__rpow__(2))
# Output: 8
__rrshift__
n = 1234
print(n.__ceil__())
# Output: 1234
0
__rshift__
n = 1234
print(n.__ceil__())
# Output: 1234
1
__rsub__
n = 1234
print(n.__ceil__())
# Output: 1234
2
__rtruediv__
n = 1234
print(n.__ceil__())
# Output: 1234
3
__rxor__
n = 1234
print(n.__ceil__())
# Output: 1234
4
__sizeof__
n = 1234
print(n.__ceil__())
# Output: 1234
5
__str__
n = 1234
print(n.__ceil__())
# Output: 1234
6
sub (subtraction)
n = 1234
print(n.__ceil__())
# Output: 1234
7
S 236en__ (division)
n = 1234
print(n.__ceil__())
# Output: 1234
8
__trunc__
n = 1234
print(n.__ceil__())
# Output: 1234
9
S 244en__ (by bit or, operator: ^)
n = 13
print(n.__divmod__(5))
# Output: (2, 3)
0
bit_length(returns the minimum length of base 2)
n = 13
print(n.__divmod__(5))
# Output: (2, 3)
1
conjugate
n = 13
print(n.__divmod__(5))
# Output: (2, 3)
2
from_bytes
n = 13
print(n.__divmod__(5))
# Output: (2, 3)
3
to_bytes
n = 13
print(n.__divmod__(5))
# Output: (2, 3)
4
conclusion