Python's Path to growth second (1) _ Data type built-in function usage

Source: Internet
Author: User
Tags abs bitwise

data type built-in function usageint

About the built-in method is very much here do a summary

(1) __abs__ (...) Returns the absolute value of x

#返回x的绝对值!!! It's all double-underlined.

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 will produce the following results:

ABS (-45): 45

ABS (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 #按位与;& operator

For example: 1010 0011

& 0000 1111

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

0000 0011

That is, with the 0 equivalent to the number of 0, and 1 is equivalent to the retention of the position

( 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 then determined based on the return value of the Python CMP comparison function.

( 5) __ Coerce __(...) compression into the same numeric type built-in mandatory Cheng Yuanju

x.__coerce__ (y) <==> coerce (x, y)

( 6) def bit_length (self) uses a binary representation of how many digits the number is at least ( 7) Division of Def_divmod_ (Self,y) to obtain a tuple consisting of quotient and remainder

x.__divmod__ (y) <==> divmod (x, y)

For paging

( 8) _DIV_ Division distributor

x.__div__ (y) <==> x/y

( 9) _float_ (convert to floating-point type)

x.__float__ () <==> float (x)

( Ten) __ Floordiv __//Operator

x.__floordiv__ (y) <==> x//y

( One ) format #格式化显示

X._format_ ("")

( ) _ getattribute __ definition can be called with a. xxx function

x.__getattribute__ (' name ') <==> x.name

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

( ) __ Getnewargs __(...)

When you read a property of an object, Python automatically calls the __getattr__ () method. For example, Fruit.color is converted to fruit.__getattr__ (color). When you set a property using an assignment statement, Python automatically calls the _ _setattr__ () method. The function of __getattribute__ () is similar to __getattr__ (), which is used to get the value of the property. But __getattribute__ () can provide better control, The code is more robust. Note that the __setattribute__ () method does not exist in Python.

( ) _ Hash _ (hash) function value

x.__hash__ () <==> hash (x)

( ) __ Hex __ () hexadecimal indicates

x.__hex__ () <==> hex (x)

( __index__ for slicing index function

( _int_ 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 0 (this does not include a string representation of the floating-point number!) Converts to a string, using an optional base. This is a mistake when converting provides a base non-string. If the base is zero, guess based on the appropriate base string content. If the parameter is in the integer range, the long object will be returned.

( __init__ is automatically executed when the class instance is created. ( _invert_ () bitwise negation; ~ operator

x.__invert__ () <==> ~x

( __long__ () Convert growth shaping

x.__long__ () <==> long (x)

( __lshift__ Move left shift;<< operator

X __lshift__ (y) <==> x<<y

( __mod__ (...) Modulo/take-out;% operator

x.__mod__ (y) <==> x%y

( ) __ Mul __(...) Multiply; * operator

x.__mul__ (y) <==> x*y

( __neg__ (...) Negative number

x.__neg__ () <==>-X

( ) __ Nonzero __ is not equal to 0

x.__nonzero__ () <==> x! = 0 defines False value for object

( __oct__) = octal

X.__oct__ () <==> Oct (x)

( ) __ or __(...) bitwise OR; | operator

x.__or__ (y) <==> x|y

( __pos__ (...) One Yuan positive

X.__pos__ () <==> +x

( ) __pow__ (...) The built-in POW (); * * operator

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

( __radd__ (...) X+y→y+x

x.__radd__ (y) <==> y+x

( ) __ Rand __(...) and Operation X&y→y&x

x.__rand__ (y) <==> y&x

( __rdiv__ (...) x/y→y/x

x.__rdiv__ (y) <==> y/x

( __rdivmod__) In addition to and modulo reverse

x.__rdivmod__ (y) <==> divmod (y, x)

( _repr__ (...) Run-time string output conversion compiler readable

x.__repr__ () <==> repr (x)

( ) __ Str __ printable character output, man-recognized

. x.__repr__ () <==> repr (x)

( Notoginseng) __r Floordiv __//operator x//y→y//x

x.__rfloordiv__ (y) <==> y//x

( 38) Other reverse Operation__rlshift__ (...) Left shift;<< operator originally X moved to the left of Y now in turn

| x.__rlshift__ (y) <==> y<<x

|

| __rmod__ (...) Modulo/take-over;% operator x%y→y%x

| x.__rmod__ (y) <==> y%x

|

| __rmul__ (...) Multiply; * operator x*y→y*x

| x.__rmul__ (y) <==> y*x

|

| __ror__ (...) bitwise OR; | operator x| y→y| X

| x.__ror__ (y) <==> y|x

|

| __rpow__ (...) The built-in POW (); * * operator

| y.__rpow__ (x[, z]) <==> pow (x, y[, z])

|

| __rrshift__ (...) Shift Right;>> operator x>>y→y>>x

| x.__rrshift__ (y) <==> y>>x

|

| __rshift__ (...) Shift Right;>> operator

| x.__rshift__ (y) <==> x>>y

|

| __rsub__ (...) minus;-Operator x-y→y-x

| x.__rsub__ (y) <==> y-x

|

| __rtruediv__ (...) True except;/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

( ) _ Truediv __ (True except;/operator)

x.__truediv__ (y) <==> x/y

( ) __ trunc __ Floating-point digital intercept shaping

Truncating an Integral returns itself.

( ) __ XOR __ Bitwise AND OR; ^ operator

x.__xor__ (y) <==> x^y

( ) Denominator the lowest condition of the denominator rational number

The denominator of a rational number in lowest terms

( imag) The imaginary part of a complex number

The imaginary part of a complex number

( minimum conditions for numerator molecular rational numbers

The numerator of a rational number in lowest terms

( Real The real part of a plural

The real part of a complex number

Python's Path to growth second (1) _ Data type built-in function usage

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.