Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Python3 built-in function of python

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

one。 Brief introduction

Python has built-in a series of commonly used functions for us to use. Python English official document details: click to view, in order to facilitate the view, record the summary of the built-in functions.

two。 instructions

Here are all the built-in functions in the Python3 version:

1. Abs () gets the absolute value

3. Any () accepts an iterator. If an element in the iterator is true, it returns True, otherwise it returns False

4. Ascii () calls the _ _ repr__ () method of the object to get the return value of the method.

5. Bin (), 6. Oct (), 7. Hex () the functions of the three functions are: convert decimal numbers to 2-8-16 digits respectively.

8. Bool () tests whether an object is True or False.

9. Bytes () converts a string to a byte type

12. Char (), 13. Ord () View the ASCII character corresponding to the decimal number / view the decimal number corresponding to an ASCII

15. Complie () compiles the string into code that python can recognize or execute, or you can read the text into a string before compiling

1 compile (source, filename, mode, flags=0, dont_inherit=False, optimize=-1) 2 compiles source into code or AST objects. Code objects can be executed through exec statements or evaluated by eval (). Parameter source: string or AST (abstract syntax trees) object. 4 parameter filename: the name of the code file, passing some recognizable values if the substitution code is not read from the file. Parameter model: specifies the type of compiled code. You can specify 'exec',' eval', 'single'. 6 parameters flag and dont_inherit: these two parameters are optional. 1 > s = "print ('helloworld')" 2 > r = compile (s, "", "exec") 3 > R4

16. Complex ()

1 create a plural with the value real + imag * j or convert a string or number to the plural. If the first parameter is a string, you do not need to specify the second parameter. 2 parameter real:int,long,float or string. 3Parametric imag:int,long,float.

17. Delattr () deletes the properties of the object

18. Dict () creates a data dictionary

20. Divmod () takes quotient and remainder respectively

1 > divmod (20pc6) 2 (3,2)

21. Enumerate () returns an object that can be enumerated, and the object's next () method returns a tuple.

25. Float () converts a string or integer to a floating point number

twenty-nine。 Globals () returns a dictionary describing the current global variable

1 > a = 12 > > globals () 3 {'_ _ loader__':,'_ _ builtins__':,'_ _ doc__': None,'_ _ name__':'_ main__','_ _ package__': None,'_ _ spec__': None}

thirty。 Hasattr ()

thirty-six。 Isinstance () checks whether the object is an object of the class and returns True or False

1 isinstance (obj, cls) 2 checks whether obj is an object of class cls and returns True or False3 class Foo (object): 4 pass5 obj = Foo () 6 isinstance (obj, Foo)

thirty-seven。 Issubclass () checks whether one class is a subclass of another. Return True or False

forty-three。 Max () returns the maximum value in a given element

1 max (iterable [, args...] [, key]) 2 if only the iterable parameter is provided, the function returns the largest non-empty element in a traverable object (such as a string, tuple, or list). 3 if more than one parameter is provided, the parameter with the highest value is returned. 4 the optional parameter key is a single-parameter sorting function. 5 if the key parameter is provided, it must be in the form of a name, such as: max (a, b, c, key = fun)

forty-four。 Meoryview ()

forty-five。 Min () returns the minimum value in a given element

1 min (iterable [, args...] [, key]) 2 if only the iterable parameter is provided, the function returns the smallest non-empty element in a traverable object (such as a string, tuple, or list). 3 if more than one parameter is provided, the parameter with the lowest value is returned. 4 the optional parameter key is a single-parameter sorting function. 5 if the key parameter is provided, it must be in the form of a name, such as: max (a, b, c, key = fun)

forty-six。 Next () returns the next item in an iterable data structure (such as a list)

forty-seven。 Object ()

1 get a new, geatureless object. Object is the base class for all classes. The methods it provides will be shared among all type instances. 2 when the function is 2.2. The version is new, and after version 2.3, the function does not accept any parameters.

forty-eight。 Open () opens the file

fifty-three。 Repr () converts any value to a string for the timer to read.

1 repr (object) 2 returns a string representation of an object. Sometimes you can use this function to access operations. 3 for many types, repr () attempts to return a string that the eval () method can use to produce an object; otherwise, a string enclosed in angle brackets containing the class name and other external information is returned.

fifty-four。 Reversed () reversal, reverse object

1 reversed (seq) 2 returns a reverse iterator object. The parameter seq must be an object that contains the _ _ reversed__ () method or supports sequential operations (_ _ len__ () and _ _ getitem__ ()) 3.

fifty-five。 Round () is rounded

sixty。 Staticmethod ()

sixty-one。 Str () string constructor

sixty-two。 Sum () summation

sixty-three。 Super () calls the method of the parent class

sixty-four。 Tuple () tuple constructor

sixty-five。 Type () displays the type to which the object belongs

sixty-six。 Vars ()

sixty-seven。 Zip () pairs objects one by one

sixty-eight。 _ _ import__ ()

Reference: https://www.cnblogs.com/xiao1/p/5856890.html

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report