Built-in functions
In short, it is the function of Python3 itself.
ABS () returns the absolute value of a number. If a complex number is given, the return value is the modulus of the complex
Print (ABS (-1100))
Output: 1100
If all elements of iterable are not 0, ', false, or iterable are empty, all (iterable) returns True, otherwise false is returned;
Print (All ([' A ', ' B ', ' C ', ' d ')) #列表list, elements are not empty or 0
Print (All ([' A ', ' B ', ' ', ' d ')) #列表list, there is an empty element
Print (All ([0,1,2,3])) #列表list, there is an element of 0
Print (All (' A ', ' B ', ' C ', ' d ')) #元组tuple, elements are not empty or 0
Print (All (' A ', ' B ', ', ' d ')) #元组tuple, there is an empty element
Print (All (0,1,2,3)) #元组tuple, there is an element of 0
Print (All ([])) # empty list
Print (All ()) # Empty tuple
Truefalsefalsetruefalsefalsetruetrue
Note: Empty tuple, empty list return value is true, here is to pay special attention to
If all elements have a value other than 0, ' ' or false, then the result is true, and when all values of iterable are 0, ' ' or false, the result is false,
Print (Any ([' A ', ' B ', ' C ', ' d ']) #列表list, the elements are not empty or 0print (any ([' A ', ' B ', ' ', ' d ')) #列表list, there is an empty element print (any ( [0,1,2,3])) #列表list, there is a 0 element print (any (' a ', ' B ', ' C ', ' d ')) #元组tuple, the elements are not empty or 0print (any (' a ', ' B ', ' ', ' d ')) #元组tuple, There is an empty element print (any (0,1,2,3)) #元组tuple, there is an element of 0 print (any ([])) # empty list print (any ()) # Empty tuple
Truetruetruetruetruetruefalsefalse
Call the __repr__ () method of the object to get the return value of the method.
Print (ASCII ([1,2,3,1,22,123])) #[1, 2, 3, 1, 22, 123]
The three function functions are: Convert the decimal number to 2 binary respectively.
Print (BIN) #0b1010
Tests whether an object is true or false.
Print (bool ([])) #False
Converts a string to a byte type
s= "Apple" v=bytes (s,encoding= "Utf-8") print (v) #b ' Apple '
The callable () function is used to test whether an object can be called, or 1 (true) if it is possible, otherwise 0 (false) is returned. Callable objects include functions, methods, code objects, classes, and class instances that have defined the calling method.
A = ' 123 ' Print (callable (a)) #False
The CHR () function returns a string corresponding to the ASCII code.
Print (CHR) #A
- Complex (Real[,imaginary])
The complex () function converts a string or number to a plural.
Print (complex (2,1)) # (2+1J)
Delete an object's properties
Create a data dictionary
Print (Dict ()) #{}
Returns the current range of variables without parameters, a list of methods and defined types, the properties of the parameters returned with parameters, a list of methods
Print (dir ())
[' __builtins__ ', ' __cached__ ', ' __doc__ ', ' __file__ ', ' __loader__ ', ' __name__ ', ' __package__ ', ' __spec__ ', ' time ']
The Divmod (x, y) function completes the division operation, returning the quotient and remainder.
Print (Divmod (10,3)) # (3, 1)
Returns an object that can be enumerated, and the next () method of the object returns a tuple
s = ["A", "B", "C"]for I, V in Enumerate (s,1):
1 A2 B3 C
Evaluates the string str as a valid expression and returns the result of the calculation
s = "1 + 3 +5" Print (eval (s)) #9
Executes a string or a string that is compiled by the Complie method, with no return value
The float () function converts a number or string into a floating point.
Print (Float (")") #12.0
Formatting the output string
Print ("I am {0},age{1}". Format ("Tom", 18))
I am tom,age18
Create a non-modifiable collection
set
和
frozenset
最本质的区别是前者是可变的,后者是不可变的。当集合对象会被改变时(例如删除,添加元素),只能使用
set
,
一般来说使用fronzet的地方都可以使用
set
。
Parameter iterable: The object can be iterated.
Returns a dictionary that describes the current global variable
A = "Apple" Print (Globals ())
{' __package__ ': None, ' __file__ ': '/users/hexin/pycharmprojects/py3/day4/2.py ', ' __name__ ': ' __main__ ', ' a ': ' Apple ', ' Time ': <module ' time ' (built-in), ' __cached__ ': None, ' __loader__ ': <_frozen_importlib_external. Sourcefileloader object at 0x10bd73c88>, ' __builtins__ ': <module ' builtins ' (built-in);, ' __spec__ ': None, ' __ doc__ ': None}
Hash valuehash
(
object
)注意:可哈希的即不可变数据类型,不可哈希即可变数据类型
如果对象
object
为哈希表类型,返回对象
object
的哈希值。哈希值为整数,在字典查找中,哈希值用于快递比价字典的键。
Two values if equal, the hash value is also equal.
Returns the Help document for an object
Call the built-in Help system, and if it does not contain parameters, the interactive Help system will start in the console. If the argument is a string, it can be a name for the module, class, method, and so on, and the help page will be printed in the console. Parameters can also be any object
The hex () function converts integers to hexadecimal numbers.
Print (hex) #0xc
Returns the memory address of an object
A = "Apple" Print (ID (a)) #4562197840
Get user input
the int () function converts numbers and strings into an integer, base is an optional cardinality.
Returns a Iterator object.
- The Len () function returns the string and the length of the sequence.
Print (len (' AA ')) #2
The list () function converts a sequence object to a list.
Print (List ("Hello World"))
[' H ', ' e ', ' l ', ' l ', ' o ', ' ', ' w ', ' O ', ' r ', ' L ', ' d ']
Print a dictionary of the currently available local variables
The max () function returns the maximum value for a given parameter, which can be a sequence.
Print (max (1,2,3,4)) #4
The min () function returns the minimum value of the given parameter, which can be a sequence.
Print (min (1,2,3,4)) #1
Returns the next item in a data structure (such as a list) that can be iterated
获取一个新的,无特性(geatureless)对象。
Object
是所有类的基类。它提供的方法将在所有的类型实例中共享。
The OCT () function converts an integer given to an octal number.
Print (Oct) #0o14
The Ord () function returns the ASCII or Unicode value of a string parameter.
Print (Ord ("a")) #97
Open Fileopen
(filename [, mode [, bufsize]])
打开一个文件,返回一个
file
对象。 如果文件无法打开,将处罚IOError异常
The POW () function returns a power of x, and y as the exponent. If the z-value is given, the function calculates the value of the Y-power of x being the z-modulo.
Print (POW (2,5)) #32print (POW (2,5,3)) #2
- Range ([Lower,]stop[,step])
The range () function generates a sequential list of ordered integers by parameter.
Print (range (1,10,2)) #range (1, 10, 2)
Converts any value to a string for the form of a timer read
Reverse, Reverse Object
The round () function returns the rounding value of the floating-point number x, if given an n value, that represents the digits rounded to the decimal point.
Print (round (5.9)) #6
Convert an object to a collection
Slicing function
s = ["A", "B" "C", "D"]print (Slice (1,3,s))
Slice (1, 3, [' A ', ' BC ', ' d '])
Sort
List sort, row by axis, higher order function, sort by absolute size, string sort, sort by ASCII size, if you need to sort a tuple, you need to use parameter key, which is the keyword. Reverse sort, reserve=true
The STR () function converts an object into a printable string.
Print (str (4)) #4
Sum
The tuple () function converts a sequence object to a tuple.
Print (Tuple ("Hello World"))
(' h ', ' e ', ' l ', ' l ', ' o ', ' ', ' w ', ' O ', ' r ', ' L ', ' d ')
The type () function returns the data type of the object.
Print (Type (' 123 ')) print (type (1))
<class ' str ' ><class ' int ' >
This function is a Dictionary object that implements the property and property values of the object that is returned. If you do not enter parameters by default, the properties and property values of the current call location are printed, equivalent to the functionality of locals (). If there is a parameter input, only the corresponding property and property values of this parameter are printed.
Print (VARs ()) #{' __name__ ': ' __main__ ', ' __spec__ ': None, ' __package__ ': None, ' __builtins__ ': <module ' builtins ' ( built-in), ' time ': <module ' time ' (built-in), ' __cached__ ': None, ' __doc__ ': None, ' __file__ ': '/users/hexin/ pycharmprojects/py3/day4/2.py ', ' __loader__ ': <_frozen_importlib_external. Sourcefileloader object at 0x10e5f3c88>}
Print (VARs (time))
View Code
Pair the objects individually
s= ' Helloo ' L=[1,2,3,4,5]z=zip (s,l) print (z) for i in Z: print (i)
<zip object at 0x1051d1608> (' h ', 1) (' E ', 2) (' L ', 3) (' L ', 4) (' O ', 5)
"Python3 inside Function"