Python's built-in approach, Abs,all,any,basestring,bin,bool,bytearray,callable,chr,cmp,complex,divmod

Source: Internet
Author: User
Tags iterable square root

Python's built-in approach

ABS (x): Returns the absolute value of a number, X can be an integer, a long integer, or a float, and if x is a plural, this method returns the absolute value of the plural (the square root of the product of this complex number and its conjugate plural)

>>> ABS (3+2J) 3.605551275463989>>> abs (3-2J) 3.605551275463989

All (iterable): This method returns true if all the elements of the iterator are true or an empty iterator.

Any (iterable): This method returns false whenever an iterator has an element of false, or an empty iterator.

basestring (): abstract type, which is a superclass of STR and Unicode, it cannot be called or instantiated, but it can be used to test an example of whether an object is not a str or Unicode. By the following means:

>>> str.isinstance (obj, basestring) >>> unicode.isinstance (obj,basestrign) >>> isinstance (obj, (str, Unicode))

bin (X): Converts an integer to a binary string, the result of which is a valid Python expression, and if X is not an int object, it must define a __index__ method that returns an integer

>>> Bin (2) ' 0B10 '

bool (X): Converts a value to a Boolean through the standard true and False check procedure. Returns False if X is false or NULL, otherwise true. It is important to note that BOOL is also a class, and is a subclass of int, and can no longer be inherited, it can only be instantiated as true or false.

ByteArray (Source[,encodeng[,errors]]): Returns an array of bytes.

callable (object): Returns True if the Parameter object can be called, or false instead. When the method returns True, the call may still fail, and if it returns false, the call must fail. It is important to note that a class can be called (a new instance is returned), and if the class instance has a __call__ method, the class instance can also be called.

chr (i): Returns a string that is the letter of an ASCII code that is an integer i. The value range of i is [0,255], if outside of this range, the method is to throw ValueError

>>> Chr ' a '
>>> chr (970) Traceback (most recent): File "<stdin>", line 1, in <MODULE>VALUEERROR:CHR () Arg not in range (256)

Classmethod (Function):

cmp (x, y): Compares objects x and Y, and returns an integer based on the comparison result. If X<y returns a negative number, returns 0 if x==y, otherwise returns an integer.

Compile (source, filename, mode[, flags[, Dont_inherit]]):

complex ([real[, Imag]]): Creates a value of real+image*j, or converts a string/number to a plural. If the first argument is a string, then the second argument must be empty, and this method converts the string to a complex number. The second argument must not be a string. Each parameter can be a numeric type (including a complex number), and if the image is empty, the default is 0, which converts the value as a method such as int (), float (). If all two parameters are empty, then 0J is returned.

It is important to note that if we want to convert a string, then there must be no space between the ' + ' or '-' of the string, as follows.

>>> complex (' 1+2j ') (1+2j) >>> complex (' 1 + 2j ') Traceback (most recent call last):  File "<stdin& gt; ", line 1, in <module>valueerror:complex () arg is a malformed string

Delattr (Object,name):

Dict (**kwarg)

Dict (Mapping,**kwarg):

Dict (Iterable,**kwarg)

Divmod (A, A, b): Returns the number pairs of quotient and remainder pairs that are the result of division by the number of two non-complex numbers as parameters. For integer and long integers, the result is (a//b, a%b), for floating-point type, the result is (q, a%b), where Q is generally math.floor (A/b), but it may also be 1 smaller than this value. Nonetheless, q*b+a%b are very close to a. If A%b is not 0, then its symbol is the same as B, and 0<=abs (a%b) <=abs (b)

>>> Divmod (10,3) (3, 1)

Built-in methods for Python, Abs,all,any,basestring,bin,bool,bytearray,callable,chr,cmp,complex,divmod

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.