1. Some built-in functions:
Coerce converts two variables to the same type.
>>> Coerce (1, 2.2)
(1.0, 2.2000000000000002)
Filter, filter (function, list) (2.
Input () enter a number
>>> A = input ("Age :")
Age: 20
>>>
20
Open (), open the file, open (filename, Mode)
Pow (x, y), POW (2, 10) = 1024
Raw_input (prompt) input string
Reduce (fun, list)
>>> Import operator
>>> Reduce (operator. Add, [1, 23])
24
Range, xrange, and xrange will not cause insufficient memory.
Len () return Length
Max (1, 2, 3) = 3
Min (1, 2, 3) = 1
Setattr (object, name, value)
Getattr (object, name)
Hasattr (object, name)
Delattr (object, name)
Type (object), type ('') = <type 'str'>
Dir () lists available syntaxes, such as: Import OS: Dir (OS)
Callable (object), whether it can be called
ABS ()
CMP (x, y), x> Y return 1, x = y return 0, x <Y, return-1
Round (Num, DEC), round (10.45, 1) = 10.5, DEC is the number of reserved decimal places.
Eval ('2*3 + 1') = 7
Exec: Execute the python statement,
>>> A = 'print "hello "'
>>> Exec
Hello
Execfile (File): Execute python in file
CHR (integer), CHR (65) = 'A ',
Ord ('A') = 65
Hex (), convert to hexadecimal. Hex (12) = 0xc
2. File Operations
Read (), read (nbytes). If there are digits, read the bytes of nbytes; otherwise, read all.
Readline () reads a row
Readlines () reads all rows and returns them as a list.
Write (), write the string.
Writelines (list), write multiple rows
The position where seek () redirects to the file. 0 indicates the beginning, 1 indicates the current, and 2 indicates the end.
Tell (), returns the current pointer.
Flush ()
Close ()