The path to Python development article 2 (1) _ data type built-in function usage, the path to python Growth

Source: Internet
Author: User

The path to Python development article 2 (1) _ data type built-in function usage, the path to python Growth
Data Type built-in function usage int

There are many built-in methods. Here is a summary.

(1) _ abs _ (...) returns the absolute value of x.

# Returns the absolute value of x !!! All are double underscores

X. _ abs _ () <=> abs (x)

For example:

#! /Usr/bin/python

Print "abs (-45):", abs (-45)

Print "abs (100.12):", abs (100.12)

Print "abs (119L):", abs (119L)

This produces the following results:

Abs (-45): 45

Abs (1, 100.12): 100.12

Abs (119L): 119

(2) _ add _ (...) Addition

A = 12

B = 1

S = a + B

Print s

13

X. _ add _ (y) <=> x + y (3) _ and _ (...) & operator

X. _ and _ (y) <==> x & y # bitwise and; & operator

For example: 1010 0011

& Amp; 0000 1111

------------------------

0000 0011

That is, it is equivalent to clearing the number of people with 0 and retaining the person with 1.

(4) _ cmp _ (self, obj) object comparison; built-in cmp ()

X. _ cmp _ (y) <=> cmp (x, y)

The cmp functions of Python can be compared between the same type or between different data types. The comparison size is determined based on the return values of the cmp comparison function in Python.

(5) _ coerce _ (...) compress to the same numeric type and forcibly generate the ancestor.

X. _ coerce _ (y) <=> coerce (x, y)

(6) def bit_length (self) uses binary to represent the minimum number of digits (7) def_divmod _ (self, y), and obtains the tuples composed of the quotient and remainder.

X. _ divmod _ (y) <=> divmod (x, y)

Used for paging

(8) _ div _ division Operator

X. _ div _ (y) <=> x/y

(9) _ float _ (converted to floating point type)

X. _ float _ () <=> float (x)

(10) _ floordiv _ // Operator

X. _ floordiv _ (y) <=> x // y

(11) format # format display

X. _ format _ ("")

(12) _ getattribute _ defines the function that can be called with. xxx

X. _ getattribute _ ('name') <=> x. name

Get attributes; built-in getattr (); always called

(13) _ getnewargs __(...)

When reading an attribute of an object, python automatically calls the _ getattr _ () method. for example, fruit. color will be converted to fruit. _ getattr _ (color ). when the attribute is set using the value assignment statement, python automatically calls the _ setattr _ () method. the function of _ getattribute _ () is similar to that of _ getattr _ (). It is used to obtain the attribute value. however, _ getattribute _ () provides better control and stronger code. note that the _ setattribute _ () method does not exist in python.

 

(14) _ hash _ (hash) function value

X. _ hash _ () <=> hash (x)

(15) _ hex _ () hexadecimal Representation

X. _ hex _ () <=> hex (x)

(16) _ index _ used for slice Indexing

 

(17) _ int _ is used to convert a number or string to an integer.

X. _ int _ () <=> int (x)

Converts a string or number to an integer if possible. A floating point parameter will be truncated to zero (this does not include a floating point represented by a string !) Converts a string to an optional basis. This is an error when the conversion provides a basic non-string. If the base is zero, guess based on the appropriate base string content. If the parameter is a long object within the Integer Range, it will be returned.

(18) _ init _ is automatically executed when the class instance is created (19) _ invert _ () reverse by bit ;~ Operator

X. _ invert _ () <=> ~ X

(20) _ long _ () convert the growth integer

X. _ long _ () <=> long (x)

(21) _ lshift _ move left to the left; <Operator

X. _ lshift _ (y) <=> x <y

(22) _ mod _ (...) modulo/remainder; % Operator

X. _ mod _ (y) <=> x % y

(23) _ mul _ (...) multiplication; * operator

X. _ mul _ (y) <=> x * y

(24) _ neg _ (...) negative number

X. _ neg _ () <=>-x

(25) _ nonzero _ Not equal to 0

X. _ nonzero _ () <=> x! = 0 defines the value of False for the object.

(26) _ oct _ indicates octal

X. _ oct _ () <=> oct (x)

(27) _ or _ (...) bitwise or; | Operator

X. _ or _ (y) <=> x | y

(28) _ pos _ (...) One dollar positive

X. _ pos _ () <=> + x

(29) _ pow _ (...) power multiplication; built-in pow (); ** Operator

X. _ pow _ (y [, z]) <=> pow (x, y [, z])

(30) _ radd _ (...) X + Y → Y + X

X. _ radd _ (y) <=> y + x

(31) _ rand _ (...) and Operations X & Y → Y & X

X. _ rand _ (y) <=> y & x

(32) _ rdiv _ (...) X/Y → Y/X

X. _ rdiv _ (y) <=> y/x

(34) _ rdivmod _ division and modulo Inversion

X. _ rdivmod _ (y) <=> divmod (y, x)

(35) _ repr _ (...) the character string output during runtime is readable by the compiler.

X. _ repr _ () <=> repr (x)

(36) _ str _ printable character output, which is recognized by people

. X. _ repr _ () <=> repr (x)

(37) _ rfloordiv _ // operator X // Y → Y // X

X. _ rfloordiv _ (y) <=> y // x

(38) Other reverse operations _ rlshift _ (...) Left shift; <operator x originally moved to the left of y.

| X. _ rlshift _ (y) <=> y <x

|

| _ Rmod _ (...) modulo/remainder; % operator X % Y → Y % X

| X. _ rmod _ (y) <=> y % x

|

| _ Rmul _ (...) multiplication; * operator X * Y → Y * X

| X. _ rmul _ (y) <=> y * x

|

| _ Ror _ (...) bitwise OR; | Operator X | Y → Y | X

| X. _ ror _ (y) <=> y | x

|

| _ Rpow _ (...) multiplication power; built-in pow (); ** Operator

| Y. _ rpow _ (x [, z]) <=> pow (x, y [, z])

|

| _ Rrshift _ (...) shifts right;> operator X> Y → Y> X

| X. _ rrshift _ (y) <=> y> x

|

| _ Rshift _ (...) shift right;> Operator

| X. _ rshift _ (y) <=> x> y

|

| _ Rsub _ (...) subtraction;-operator X-Y> Y-X

| X. _ rsub _ (y) <=> y-x

|

| _ Rtruediv _ (...) True division;/operator X/Y → Y/X

| X. _ rtruediv _ (y) <=> y/x

|

| _ Rxor _ (...) bitwise AND or; ^ operator X ^ Y → Y ^ X

| X. _ rxor _ (y) <=> y ^ x

|

| _ Str _ (...) printable character output; built-in str () and print statements

| X. _ str _ () <=> str (x)

|

| _ Sub _ (...) minus;-Operator

| X. _ sub _ (y) <=> x-y

(39) _ truediv _ (True division;/operator)

X. _ truediv _ (y) <=> x/y

(40) _ trunc _ Floating Point Digital truncation and shaping

Truncating an Integral returns itself.

(41) _ xor _ bitwise AND or; ^ Operator

X. _ xor _ (y) <=> x ^ y

(42) minimum condition for denominator rational number

The denominator of a rational number in lowest terms

(43) imag a plural imaginary part

The imaginary part of a complex number

(44) Minimum rational number of numerator molecules

The numerator of a rational number in lowest terms

(45) real is a complex real part.

The real part of a complex number

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.