1. Mathematical operations
ABS (-5) # take absolute value, i.e. 5
Round (2.6) # rounded rounding, which is 3.0
Pow (2, 3) # equivalent to 2**3, if it is POW (2, 3, 5), equivalent to 2**3% 5
CMP (2.3, 3.2) # Compare the size of two numbers
Divmod (9,2) # returns the division result and remainder
Max ([1,5,2,9]) # Ask for maximum value
MIN ([9,2,-4,2]) # to find the minimum value
SUM ([2,-1,9,12]) # sum
2. Type conversion
Int ("5") # is converted to an integral integer
Float (2) # Convert to floating-point float
Long ("23") # converts to a long integer long
STR (2.3) # converts to string strings
Complex (3, 9) # returns complex number 3 + 9i
Ord ("A") # "a" character corresponding value
Chr (65) # Number 65 corresponds to the character
UNICHR (65) # VALUE 65 corresponds to the Unicode character
BOOL (0) # is converted to the corresponding true and False value, and in Python 0 is equivalent to false. In Python, the following objects are equivalent to false:** [], (), {}, 0, None, 0.0, "* *
Bin (56) # Returns a String representing a binary number of 56
Hex (56) # Returns a String that represents the hexadecimal number of 56
Oct (56) # Returns a String that represents the octal number of 56
List (()) # Convert to Table list
Tuple ([2,3,4]) # Convert to fixed value table tuple
Slice (5,2,-1) # Build Subscript Object Slice
Dict (a=1,b= "Hello", c=[1,2,3]) # Build Dictionary Dictionary
3. Sequence operation
All ([True, 1, "hello!"]) # If all elements are equal to True values
Any (["", 0, False, [], None]) # is there any one element equal to the true value
Sorted ([1,5,3]) # Returns the sequence of the positive sequence, i.e. [1,3,5]
Reversed ([1,5,3]) # Returns the sequence of the reverse order, i.e. [3,5,1]
4. Classes, objects, attributes
# define Class
Class Me (object):
def test (self):
Print "Hello!"
Def new_test ():
Print "New hello!"
me = Me ()
Hasattr (Me, "Test") # Check if the Me object has a test property
GetAttr (Me, "test") # Returns the Test property
SetAttr (Me, "test", New_test) # Set the test property to New_test
Delattr (Me, "test") # Delete test property
Isinstance (Me, Me) # Me object is the object generated by the Me class (a instance)
Issubclass (Me, Object) # Me class is a subclass of the object class
5. Compiling and executing
Repr (Me) # Returns the string representation of an object
Compile ("Print (' Hello ')", ' test.py ', ' exec ') # Compile string becomes code object
Eval ("1 + 1") # interprets the string expression. The parameter can also be a code object returned by the compile ()
EXEC ("Print (' Hello ')") # interprets and executes the string, print (' Hello '). The parameter can also be a code object returned by the compile ()
6. Other
Input ("Please input:") # Wait for input
Globals () # Returns the global namespace, such as global variable name, global function name
Locals () # returns the local namespace
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