1. Python Custom functions
The function code block that the user has written in Python to implement a particular function is the custom function.
such as: def is a keyword, SAA is a custom function name, parentheses are used to pass parameters, you can not write arguments, the colon is followed by a function code block, here only a print statement is written
Note: The function does not call do not execute , only the calling function will execute
Little Exercise 1:
The execution results are:
:
Come and see a little Practice 2:
This is a small program used to generate color ball, such as blue ball number 01 red ball 22 12 23 14 05 26, Blue Ball number range 1-16, red ball number range 1-33, last line call produce () custom function.
Execution results are
2, python commonly used built-in functions
As in the example above, print is a built-in function in Python, which summarizes some common built-in functions
Print (All ([1,2,3,4])) #判断可迭代的对象里面的值是否都为真
Print (Any ([0,1,2,3,4])) #判断可迭代的对象里面的值是否有一个为真
Print (BIN) #十进制转二进制
Print (bool (' s ')) #把一个对象转换成布尔类型
Print (CHR) #打印数字对应的ascii
Print (ord (' B ')) #打印字符串对应的ascii码
Print (dir (1)) #打印传入对象的可调用方法
Print (EXEC (' Def a ():p ') ') #执行python代码
Print (filter (lambda x:x>5,[12,3,12,2,1,2,35)) #把后面的迭代对象根据前面的方法筛选
Print (Map (lambda x:x>5,[1,2,3,4,5,6))
Print (max (111,12)) #取最大值
Print (Round (11.11,2)) #取几位小数
Print (sorted ([2,31,34,6,1,23,4])) #排序
Python custom functions, common built-in functions