python notes of built-in functions common learning

python provides many built-in functions to learn about these internal functions can be called directly when the built-in function in some cases just need to implement function when not required to write additional code, such as: selecting the maximum value directly max (), etc.

1, abs () absolute value

1 a=-99
2 print(abs(a))

2, help () View help view function modules use or detailed description for the parameters in parentheses class object

. 1 Help ( ' STR ' ) # See methods which string 
2  
. 3 A = [l, 2,3 ]
 . 4 Help (a.append)   # view of a particular method of use

3, dir () Returns the attributes of the parameters, the list method, the object may be a parameter, variable, type

1 by aa = [1,2,3 ]
 2  Print ( the dir ( by aa))

4, max () min () maximum and minimum values

. 1 AA = [2,55,344,22,33,55,66 ]
 2  Print (max (AA)) # maximum 
. 3  Print (min (AA)) # Min

5, chr (), ord () number to String, String to digital (only a single character)

1 bb=89
2 print(chr(bb))
3 
4 print(ord('a'))

6, sorted function operation on all sorts of objects iterations

1 dict1 = {'name':'python','age':'20','address':'sz'}
2 print(sorted(dict1.items(),key=lambda item:item[0]))

7, map () function is provided to do according to the specified sequence mapping, map actually is an iterator

map(function, iterable, ...)

function - Function

iterable - one or more sequences

1 def fun(a):
2     return a**2
3 
4 list1 = [1,2,3,4,5,6]
5 print(list(map(fun,list1)))

8, filter () for filtering a sequence filter out ineligible element returns an iterator object

. 1  DEF fun1 (A):
 2      IF A> 10 :
 . 3          return A
 . 4  
. 5 list3 = [1,3,33,1,22,0,99 ]
 . 6  Print (List (filter (fun1, list3))) # Filter out of 10 less than the number

9, isinstance () determines whether an object of a type known

. 1 str1 = ' A ' 
2  Print (the isinstance (str1, STR)) # result is True 
. 3  Print (the isinstance (str1, int)) # result is False

 

Guess you like

Origin www.cnblogs.com/heertong/p/12114539.html