1. abs()

grammar

Abs (x), returns the absolute value of a number. The argument can be an integer or a floating-point number. If the argument is a complex number, its magnitude is returned

The sample

2. all()

grammar

All (iterable), which returns True if all elements of iterable are True (or if iterable is empty)

The equivalent code is as follows:

def all(可迭代) :
    for element in iterable:
        if not element:
            return False
    return True
Copy the code

3. any()

grammar

Any (iterable), which returns True if any element of iterable is True and False if the iterable is empty

The equivalent code is as follows:

def any(可迭代) :
    for element in iterable:
        if element:
            return True
    return False
Copy the code

4. ascii()

grammar

ASCII (object) : returns the pure ASCII representation of an object.

The ASCII () function is similar to the repr() function in that it returns a string representing an object, but for non-ASCII characters in the string it returns a character encoded by repr() using \x, \u, or \u.

The generated string is similar to the return value of the repr() function in the Python2 version.

5. bin()

grammar

Bin (x), which converts an integer to a binary string prefixed with “0b”

6.bool()

grammar

Returns a Boolean value, True or False, or False if there are no arguments

Bool is a subclass of int

7. breakpoint()

grammar

Breakpoint (*args, ** KWS), which calls sys.breakpointhook(), passing args and KWS directly into the PDB debugger

This is rarely used, hardly ever…

8.bytearray()

grammar

class bytearray([source[, encoding[, errors]]])
Copy the code

If source is an integer, an initialized array of length source is returned;

If source is a string, the encoding argument must be supplied. Converts the string to a sequence of bytes according to the specified encoding;

If source is iterable, the element must be an integer in [0,255];

If the source is an object consistent with the buffer interface, this object can also be used to initialize bytearray.

If no arguments are entered, an array of size 0 is created.

9.bytes()

grammar

The bytes() function returns a new bytes object that is an immutable sequence of integers in the range 0 <= x < 256. It is an immutable version of Bytearray.

10.callable()

grammar

Callable (object), used to check whether an object is callable, returns True if it is called, False otherwise

If True is returned, the call to object may still fail, but if False is returned, the call to object will definitely fail

In addition, the class is callable, and the calling class returns a new instance

It is also callable if the class to which the instance belongs has a __call__() method.

11.chr()

grammar

CHR (I), returns the ASCII character of the argument, I: a decimal or hexadecimal number ranging from 0 to 1,114,111 (0x10FFFF in hexadecimal).

12.classmethod()

grammar

Encapsulate a method as a class method that requires no instantiation, no self argument, and the first argument is a CLS argument representing its own class

It can be used to call properties of a class, methods of a class, etc

13.compile()

grammar

compile(source, filename, mode, flags=0, dont_inherit=False, optimize=-1)
Copy the code

Compile the source into code or AST objects. Code objects can be executed by exec() or eval().

Source: Can be a regular string, byte string, or AST object

Filename: The name of the code file, passing some recognizable value if the code is not read from the file.

Mode: Specifies the type of compiled code. You can specify exec, eval, single.

Flags: Variable scope, local namespace, if provided, can be any mapping object.

Flags and dont_inherit are flags used to control compiling source code.

14.complex()

grammar

class complex([real[, imag]])
Copy the code

A complex number that returns the value real + imag*1j or converts a string or number to a complex number.

If the first parameter is a string, it is interpreted as a complex number, and the function call cannot have a second parameter

parameter

_real_ : int, long, float or string.

_imag_ : int, long, float cannot be strings

15. delattr()

grammar

delattr(object, name)
Copy the code

The argument is an object and a string. The string must be an attribute of the object. This function deletes the specified property if the object allows it.

16. dict()

grammar

class dict(**kwarg)
class dict(mapping, **kwarg)
class dict(iterable, **kwarg)
Copy the code

Create a new dictionary

parameter

**kwargs: keyword mapping: container of elements. Iterable: iterable object.

17. dir()

grammar

Dir ([object]), if called with no arguments, returns the name in the current range.

Returns a list of attributes and methods for a parameter

18.divmod()

grammar

Divmod (a, b), the function takes two numeric (non-complex) arguments and returns a tuple (a // b, a % b) containing the quotient and remainder.

19.enumerate()

grammar

Enumerate (iterable, start=0), returns an enumeration object. Iterable must be a sequence, an iterator, or some other object that supports iteration

The sample

>>> codes = ['Python'.'Java'.'GO'.'C++']
>>> list(enumerate(codes, start=2[())2.'Python'), (3.'Java'), (4.'GO'), (5.'C++')]
Copy the code

20.eval()

grammar

eval(expression[, globals[, locals]])
Copy the code

parameter

Expression: Python expression.

Globals: must be a dictionary object.

Locals: Variable scope, local namespace, which can be any mapping object if provided.

Executes a string expression and returns the value of the expression

21.exec()

grammar

exec(object[, globals[, locals]])
Copy the code

Exec executes Python statements stored in strings or files, and can execute more complex Python code than eval.

parameter

Object: This parameter is mandatory. It must be a string or code object. If object is a string, the string is parsed as a set of Python statements and then executed (unless a syntax error occurs). If object is a code object, it is simply executed.

Globals: An optional parameter that indicates that the global namespace (holding global variables) must be a dictionary object.

Locals: This parameter is optional, indicating that the local namespace can be any mapping object. If this parameter is ignored, it will take the same value as globals.

22.filter()

grammar

filter(function, iterable)
Copy the code

The filter() function is used to filter a sequence, filter out elements that do not meet the criteria, and return an iterator object that can be converted to a list using list().

This takes two arguments, the first a function and the second a sequence. Each element of the sequence is passed as an argument to the function for evaluation, and then returns True or False. Finally, the element that returns True is placed in the new list.

23.float()

grammar

Converts integers and strings to floating point numbers.

24.format()

grammar

Format (value[, format_spec]). Format (value[, format_spec]). Use {} and: instead of %

The format function can take unlimited arguments and positions out of order.

25.frozenset()

grammar

class frozenset([iterable])
Copy the code

Frozenset () returns a frozen collection after which no more elements can be added or removed.

26.getattr()

grammar

getattr(object, name[, default])
Copy the code

Returns the value of the named property of the object. Name must be a string. If the string is one of the properties of the object, the value of that property is returned.

For example, getattr(x, ‘foobar’) is equivalent to x.foobar. If the specified attribute does not exist and a default value is provided, it is returned, otherwise AttributeError is raised

27.globals()

grammar

Returns a dictionary containing the global variables of the current scope.

28.hasattr()

grammar

Hasattr (object, name), the argument is an object and a string. Returns True if the string is the name of one of the object’s properties, False otherwise.

This is done by calling getattr(Object, Name) to see if there is an AttributeError exception.

29.hash()

grammar

Hash (object), returns the hash value of the object

The hash() function applies to numbers, strings, and objects, but not directly to lists, sets, and dictionaries.

30.help()

grammar

View the help information for a function that provides you with help

31.hex()

grammar

Hex (x) : converts an integer to a lowercase hexadecimal string prefixed with 0x.

32.id()

grammar

Id (object) : Returns the memory address of the object

33.input()

grammar

The input() function takes standard input data and returns a string.

In Python3.x, raw_input() and input() are combined to remove raw_input(), leaving only the input() function, which takes arbitrary input, treats all input as strings by default, and returns a string type.

34.int()

grammar

Converts a string or number to an integer.

35.isinstance()

grammar

isinstance(object, classinfo)
Copy the code

The isinstance() function checks whether an object is of a known type, similar to type(). I sinstance() differs from Type () : Type () does not consider a subclass to be a superclass type, regardless of inheritance.

Isinstance () considers a subclass to be a superclass type, considering inheritance.

Isinstance () is recommended to determine whether two types are the same.

36.issubclass()

grammar

issubclass(class.classinfo)
Copy the code

The issubClass () method is used to determine whether the class argument is a subclass of the type argument classinfo.

37.iter()

grammar

iter(object[, sentinel])
Copy the code

Returns an iterator object

If the second argument is passed, the object argument must be a callable object. At this point, iter creates an iterator object that will be called every time its next() method is called.

38.len()

grammar

Returns the length of the object

39.list()

grammar

Converts a tuple or string to a list

40.locals()

grammar

Function locals() returns all local variables of the current location as dictionary types.

41.map()

grammar

map(function, iterable, ...)
Copy the code

Returns an iterator that applies function to each item in iterable and prints the result

42.max()

grammar

Returns the largest element in the iterable

43.memoryview()

grammar

Returns the memory view for the given argument

44. min()

grammar

Returns the smallest element in the iterable, or the smallest of two or more arguments.

45.next()

grammar

Get the next element by calling iterator’s __next__() method. If the iterator is exhausted, the given default is returned, and StopIteration is raised if there is no default.

46.object()

grammar

Returns a new object with no characteristics. Object is the base class of all classes.

It has methods common to all Instances of Python classes. This function does not take any arguments.

47. oct()

grammar

Returns the octal representation of an integer

48.open()

grammar

open(file, mode='r', buffering=-1, encoding=None, errors=None, newline=None, closefd=True, opener=None)
Copy the code

The open() function opens a file and returns a file object. This function is used during any processing of the file and raises OSError if the file cannot be opened

49.ord()

grammar

For a single character string, return its Unicode encoded integer

For example ord(‘a’) returns the integer 97, and ord(‘€’) (euro symbol) returns 8364. It’s the inverse of CHR of alpha.

50. pow()

grammar

pow(base, exp[, mod])
Copy the code

The function computes base to the power exp, and modulates the result if the mod exists. The result is equivalent to pow(base,exp) %mod.

51.print()

grammar

print(*objects, sep=' ', end='\n', file=sys.stdout, flush=False)
Copy the code

Print objects to the text stream specified by file, sys.stdout by default

52.property()

grammar

The property() function returns the value of the property in the new class.

53.range()

grammar

The range() function returns an iterable

54.repr()

grammar

Returns a string containing a printable representation of an object. For most types, eval(repr(obj)) == obj

55.reversed()

grammar

Returns a reverse iterator to the given sequence value

56.round()

grammar

Returns the value of number rounded to ndigits precision after the decimal point. If ndigits is omitted or None, the integer closest to the input value is returned

For those with high precision requirements, this function is not reduced

57.set()

grammar

The set() function creates an unordered set of non-repeating elements, removes duplicate data, and can be used to calculate intersections, difference sets, unions, and so on.

58.setattr()

grammar

setattr(object, name, value)
Copy the code

Its arguments are an object, a string, and an arbitrary value, setting the named property on the given object to the specified value.

For example, setattr(python, ‘name’, 123) is equivalent to python.name= 123

59.slice()

grammar

The slice() function implements slice objects, mainly used for parameter passing in the slice operation function.

60.sorted()

grammar

sorted(iterable, key=None, reverse=False)
Copy the code

Sort all iterable objects in ascending order by default

Sort differs from sorted: Sort is a method applied to a list that sorts all iterable objects.

The sort method returns an operation on an existing list

The sorted method returns a new list

61.staticmethod()

grammar

Convert a method to a static method that does not cost you to pass parameters

62.str()

grammar

Returns the string format of an object

63.sum()

grammar

Sum (iterable[, start]), the sum of iterable items from left to right from start and returns the total value

64.super()

grammar

A method used to call a parent class to solve multiple inheritance problems

The sample

65. tuple()

grammar

Converts an iterable series, such as a list, to a tuple

66.type()

grammar

The type of Object is returned when one argument is passed, and a new Type object is returned when three arguments are passed

>>> class X:
          a = 1

>>> X = type('X', (object,), dict(a=1))
>>> X
<class '__main__.X'>

Copy the code

67.vars()

grammar

Returns the __dict__ attribute of a module, class, instance, or any other object that has a __dict__ attribute.

68. zip()

grammar

Used to take an iterable object as an argument, pack the corresponding elements of the object into tuples, and then return an object composed of these tuples

The list() conversion can be used to output the list, and if the iterators have an inconsistent number of elements, the shortest object will be returned

The sample

69. _import_ ()

grammar

__import__(name, globals=None.locals=None, fromlist=(), level=0)
Copy the code

The _import()_ function is used to dynamically load classes and functions.

If a module changes frequently it can be loaded dynamically using _import()_

These are all 69 Python built-in functions, based on Python3.8.6 syntax rules