Python built-in functions

Source: Internet
Author: User
Tags iterable
Python built-in functions have been learning python recently. on the Internet, I have learned some types of python built-in functions and the functions of built-in functions. The following is a list of python built-in functions, the beginner's understanding may be inaccurate in classification and can communicate with each other. I. mathematical operation abs (x) calculates the absolute value. 1. the parameter can be an integer or a complex number. 2. if the parameter is a complex Python built-in functionsI have been learning python recently. I have seen and learned some types and functions of python built-in functions on the internet. Below are some examples of python built-in functions. for beginners, the classification may be inaccurate and can be communicated together.
I. mathematical operations

Abs (x)
Absolute value
1. the parameter can be an integer or a plural value.
2. if the parameter is a plural value, the modulo of the plural value is returned.
Complex ([real [, imag])
Create a plural number
Pmod (a, B)
Separate operator and remainder
Note: integer and floating point types are supported.
Float ([x])
Converts a string or number to a floating point number. If no parameter exists, 0.0 is returned
Int ([x [, base])
Converts a character to the int type. base indicates hexadecimal
Long ([x [, base])
Converts a character to the long type.
Pow (x, y [, z])
Returns the Power y of x.
Range ([start], stop [, step])
Generates a sequence, starting from 0 by default.
Round (x [, n])
Rounding
Sum (iterable [, start])
Sum a set
Oct (x)
Convert a number to an octal number.
Hex (x)
Convert integer x to a hexadecimal string
Chr (I)
Returns the ASCII character corresponding to integer I.
Bin (x)
Convert integer x to a binary string
Bool ([x])
Convert x to Boolean type

II. collection operations

Basestring ()
Str and unicode superclass
It cannot be called directly. it can be used as an isinstance for judgment.
Format (value [, format_spec])
Format the output string
The formatted parameter sequence starts from 0, for example, "I am {0}, I like {1 }"
Unichr (I)
Returns unicode of the given int type.
Enumerate (sequence [, start = 0])
Returns an enumerated object. the next () method of this object returns a tuple.
Iter (o [, sentinel])
Generate an object iterator with the second parameter representing the separator
Max (iterable [, args...] [key])
Returns the maximum value in the set.
Min (iterable [, args...] [key])
Returns the minimum value in the set.
Dict ([arg])
Create a data dictionary
List ([iterable])
Converts a collection class to another collection class.
Set ()
Set object instantiation
Frozenset ([iterable])
Generate an unchangeable set
Str ([object])
Convert to string type
Sorted (iterable [, cmp [, key [, reverse])
Sort a group
Tuple ([iterable])
Generate a tuple type
Xrange ([start], stop [, step])
The xrange () function is similar to range (), but xrnage () does not create a list, but returns an xrange object. Its behavior is similar to the list, however, the list value is calculated only when needed. when the list is large, this feature can save us memory.

III. logical judgment

All (iterable)
1. all elements in the set are true
2. in particular, True is returned if it is an empty string.
Any (iterable)
1. one element in the set is true.
2. in particular, if it is an empty string, False is returned.
Cmp (x, y)
If x Y, returns a positive number.

IV. reflection

Callable (object)
Check whether the object is callable
1. classes can be called.
2. the instance cannot be called unless the _ call _ method is declared in the class.
Classmethod ()
1. annotation, used to indicate that this method is a class method
2. a class method can be called by a class or an instance.
3. the class method is similar to the static method in Java.
4. the self parameter is not required in class methods.
Compile (source, filename, mode [, flags [, dont_inherit])
Compile source as a code or AST object. Code objects can be evaluated using exec statements or eval.
1. parameter source: string or AST (Abstract Syntax Trees) object.
2. filename: name of the code file. if the code is not read from the file, some identifiable values are passed.
3. parameter model: specifies the type of the compiled code. You can specify it as 'exec ', 'eval', and 'singles '.
4. parameters flag and dont_inherit
Dir ([object])
1. If no parameter is specified, a list of variables, methods, and definitions in the current range is returned;
2. when a parameter is included, the attribute and method list of the parameter are returned.
3. if the parameter contains method _ dir _ (), this method will be called. When the parameter is instance.
4. if the parameter does not contain _ dir _ (), this method collects parameter information to the maximum extent.
Delattr (object, name)
Delete the property of the object named name
Eval (expression [, globals [, locals])
Calculates the expression value.
Execfile (filename [, globals [, locals])
The usage is similar to exec (). The difference is that the filename parameter of execfile is the file name, while the exec parameter is a string.
Filter (function, iterable)
Construct a sequence, equivalent to [item for item in iterable if function (item)]
1. function: a function with a return value of True or False, which can be None.
2. parameter iterable: sequence or iteratable object
Getattr (object, name [, defalut])
Obtains the attributes of a class.
Globals ()
Returns a dictionary describing the current global symbol table.
Hasattr (object, name)
Determines whether an object contains a feature named name.
Hash (object)
If the object is of the hash table type, the hash value of the object is returned.
Id (object)
Unique identifier of the returned object
Isinstance (object, classinfo)
Judge whether the object is a class instance
Issubclass (class, classinfo)
Determine whether it is a subclass
Len (s)
Returns the length of the set.
Locals ()
Returns the current variable list.
Map (function, iterable ,...)
Traverse each element and perform function operations
Memoryview (obj)
Returns an object of the memory image type.
Next (iterator [, default])
Similar to iterator. next ()
Object ()
Base Class
Property ([fget [, fset [, fdel [, doc])
The packaging class for attribute access. after setting, you can access setter and getter through c. x = value.
Reduce (function, iterable [, initializer])
The merge operation starts with the first two parameters, then the first two results are merged with the third, and so on.
Reload (module)
Reload the module
Setattr (object, name, value)
Set attribute values
Repr (object)
Change an object to a printable format
Slice ()

Staticmethod
Declares a static method. it is an annotation.
Super (type [, object-or-type])
Reference parent class
Type (object)
Returns the type of the object.
Vars ([object])
Returns the variable of the object. If no parameter exists, it is similar to the dict () method.
Bytearray ([source [, encoding [, errors])
Returns a byte array.
1. if source is an integer, an initialized array with the source length is returned;
2. if source is a string, the string is converted to a byte sequence based on the specified encoding;
3. if source is an iteration type, the element must be an integer in [0,255;
4. if source is an object consistent with the buffer interface, this object can also be used to initialize bytearray.
Zip ([iterable,...])
I did not understand it. I just saw the changing aspects of the matrix.

V. IO operations

File (filename [, mode [, bufsize])
The file type constructor is used to open a file. if the file does not exist and the mode is write or append, the file will be created. Add 'B' to the mode parameter to operate the file in binary format. Adding '+' to the mode parameter will allow simultaneous read/write operations on the file
1. filename: file name.
2. parameter mode: 'R' (read), 'W' (write), and 'A' (append ).
3. parameter bufsize: if it is 0, it indicates no buffer. if it is 1, it indicates row buffering. if it is a number greater than 1, it indicates the buffer size.
Input ([prompt])
Get user input
Raw_input is recommended because this function will not capture users' incorrect input.
Open (name [, mode [, buffering])
Open a file
What is the difference with file? Open is recommended.
Print
Print function
Raw_input ([prompt])
Set input. all input values are processed as strings.

VI. othersHelp () -- help information apply (), buffer (), coerce (), intern () --- these are expired built-in functions, so it is not describedVII. postscriptBuilt-in functions are generally provided in the form of built-in functions because they are frequently used or meta operations. you can see from the classification analysis of python built-in functions: basic data operations are mathematical operations (except addition, subtraction, multiplication, division, division), logical operations, set operations, basic IO operations, reflection operations for the language itself, and string operations, it is also quite common, especially the reflection operation.

The above is a detailed description of python built-in functions. For more information, see other related articles in the first PHP community!

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.