美文网首页
2017-05-02/Python3.x-函数_by:Hello

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

作者: Hello_jeo | 来源:发表于2017-05-02 21:43 被阅读0次

函数分类

内置函数

内建函数
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. 递归函数:在函数内部,可以调用其他函数。如果一个函数在内部调用自身本身,这个函数就是递归函数。[汉诺塔]
  • 可变参数:参数前面+*号,*nums,num接收到的是一个tuple,可以接收任意个参数,包括0个。
  • 关键字参数:参数前面+**号**uk,uk接收到的是一个dict,包括所有的key-value,**uk并不会影响函数外的uk本身
  • 命名关键字参数:def person(name, age, *, city, job): print(name, age, city, job)
  • 参数定义的顺序必须是:必选参数、默认参数、可变参数、命名关键字参数和关键字参数。

相关文章

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

    函数分类 内置函数 内建函数可直接调用,不用定义。参考:python官方帮助文档 自定义函数 语法: 要点: 函数...

  • shell-12 函数 nginx脚本

    函数的语法 函数的应用定义一个函数 hello就是函数名print 和 hello就是函数的名字,函数名字命名参考...

  • 第六部分函数、数据结构

    def hello(): print('hello,world!') hello() #带参数变量的函数 #计...

  • Lua中的函数拾遗

    函数 例一 hello函数不接收参数,调用:hello(),虽然hello不接收参数,但是还可以可以传入参数:he...

  • སློབ་ཆུང་སློབ་མ་འགའ་ཞིག་གི་སེམས་

    ལི་སྨད་སློབ་ཆུང་གི་སློབ་མའི་རྩོམ་འགའ། 2017-05-02 ཉི་གཞོན།...

  • 普通函数和箭头函数的this指向

    普通函数与箭头函数 普通函数指的是用 function 定义的函数: var hello = function()...

  • Flutter之Dart基础

    一. Hello Dart 1.1 Hello Dart 和大多数语言一样,Dart的入口函数也是Main函数,新...

  • js函数

    函数函数就是重复执行的代码片。函数定义与执行 // 函数定义function aa(){alert('hello!...

  • 函数

    函数函数就是重复执行的代码片。函数定义与执行 // 函数定义function aa(){alert('hello!...

  • js

    函数函数就是重复执行的代码片。函数定义与执行 // 函数定义function aa(){alert('hello!...

网友评论

      本文标题:2017-05-02/Python3.x-函数_by:Hello

      本文链接:https://www.haomeiwen.com/subject/sjactxtx.html