2017-05-02/Python3.x-函数_by:Hello

2017-05-02  本文已影响0人  Hello_jeo

函数分类

内置函数

内建函数
abs() dict() help() min() setattr()
all() dir() hex() next() slice()
any() divmod() id() object() sorted()
ascii() enumerate() input() oct() staticmethod()
bin() eval() int() open() str()
bool() exec() isinstance() ord() sum()
bytearray() filter() issubclass() pow() super()
bytes() float() iter() print() tuple()
callable() format() len() property() type()
chr() frozenset() list() range() vars()
classmethod() getattr() locals() repr() zip()
compile() globals() map() reversed() import()
complex() hasattr() max() round() -
delattr() hash() memoryview() set() -

内建函数可直接调用,不用定义。
参考:python官方帮助文档

自定义函数

语法:

def add (a,b)
    return a+b

要点:

  1. 函数名不要用内建函数名,否则内建函数失效。
  2. 函数参数,需理解“默认参数”、“可变参数”、“关键字参数”、“命名关键字参数”。
  3. 递归函数:在函数内部,可以调用其他函数。如果一个函数在内部调用自身本身,这个函数就是递归函数。[汉诺塔]
上一篇 下一篇

猜你喜欢

热点阅读