Python int inside function introduction

Source: Internet
Author: User

Introduction to int internal functions

You can view all the functions inside an int by using the Dir (value of type int) or by CTRL + click Int. Internal functions are many, but many of the internal functions are not commonly used, the following are commonly used in some of the internal functions

Type ()

1. When using the type () function for the base data type, the corresponding data type is obtained
A = 12
b = 12.01
c = "123"
Print (Type (a)) >>> int
Print (type (b)) >>> float
Print (Type (c)) >>> str
2. When other classes use the type () function, get the location of the class
From twisted.internet Import reactor
Print (Type (reactor)) >>> Twisted.internet.selectreactor.SelectReactor

Bit_length ()

Returns the minimum number of digits that the number occupies
Age = 18
Print (BIN) >>> 0b10010
0001 0010
Print (Age.bit_length ()) >>> 5

__abs__ ()

Return absolute Value
Age = 18
Score =-100
Print (age.__abs__ ()) or print (ABS (age)) >>> 18
Print (score.__abs__ ()) or print (ABS (score)) >>> 100

__add__ (Self,y)

Two numbers added
A = 1
b = 2
Print (a.__add__ (b)) or print (A+B) >>> 3

__and__ (Self,y)

Ask for two numbers of
A = 1
b = 2
Print (a.__and__ (b)) >>> 0

__DIVMOD__ ()

Computes the division of two numbers, obtains a meta-ancestor, the first of the Ganso is the quotient, the second is the remainder. This method is more commonly used in pagination, which is more important.
All_item = 95
Pager = 10
result = all_item.__divmod__ (pager)
Print (Result) >>> (9,5)

__RDIVMOD__ ()

Swap the position of two digits and divide

Note: Like __radd__, __rand__, __rdiv__ .... All the previous r's are swapped two number positions, and then do the arithmetic

__EQ__ ()

Determine if two numbers are equal
A = 18
result = a.__eq__ (19)
Print (result) >>> False
Print (18==19) >>> False

__float__ ()

convert int to float
Age = 18
Print (Type (age)) >>>int
result = age.__float__ ()
Print (type result) >>>float

__FLOORDIV__ ()

Divide two numbers, only a reserved quotient
Age = 5
result = age.__floordiv__ (6)
Print (Result) >>> 0
Print (5//6) >>> 0

__init__ ()

How to construct an int class
Perform
age = Int (19)
The construction method is executed

__POW__ ()

exponentiation
A = 2
b = 2
Print (a.__pow__ (b)) >>> 4
Print (A**B) >>> 4

........

other int internal functions can be self-understanding, the above are often used!

Python int inside function introduction

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.