List of Python built-in functions

巴扎黑
Release: 2016-12-03 10:52:03
Original
1422 people have browsed it

1. Mathematical operations
abs(-5)                                                                                                                                                                                                                                           ​                 # Equivalent to 2**3, if it is pow (2, 3, 5), equivalent to 2**3 % 5
cmp(2.3, 3.2)                                                                                                                    ,2,9]) # Find the maximum value
min([9,2,-4,2]) # Find the minimum value
sum([2,-1,9,12]) # Find the sum

2. Type Convert
int("5") # Convert to integer
float(2) # Convert to floating point number float
long("23") # Convert to long integer
str(2.3)                                   # Convert to string
complex(3, 9)                   # Return the complex number 3 + 9i                                                                                                     The character corresponding to 65
unichr(65)                   # The unicode corresponding to the value 65 Character lBool (0) # Convert to the corresponding authentic values. In Python, 0 is equivalent to false. In python, the following objects are equivalent to false: ** [], (), {}, 0, none , 0.0, '' **

bin(56)                                                                                                                                                       6)                       # Return A string representing the octal number 56

list((1,2,3))                                                                                                                ,-1)                                                                                                                                                                                    , "hello!"]) # Whether all elements are equivalent to True value
any(["", 0, False, [], None]) # Whether any element is equivalent to True value

sorted([1 )Reversed ([1,5,3]) # Returns the sequence of the backflow, which is [3,5,1]

4, class, object, attributes
# define class
Class me (Object):
DEF TEST ( self): ​​​me, "test") # Return the test attribute
setattr(me, "test", new_test) # Set the test attribute to new_test
delattr(me, "test") # Delete the test attribute
isinstance(me, Me) # me Whether the object is an object generated by the Me class (an instance)
issubclass(Me, object) # Whether the Me class is a subclass of the object class

5. Compilation and execution
repr(me) # Return the string expression of the object
compile ("Print ('hello')", 'test.py', 'exec') # compile string becomes CODE object
eval ("1 + 1") # Explanation string expression. The parameter can also be the code object returned by compile()
exec("print('Hello')")               # Interpret and execute the string, print('Hello'). The parameter can also be the code object returned by compile()

6, others
input("Please input:")                                                                                                                                                                                                 # Return to local namespace

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template