芙姬情感网
您的当前位置:首页《python基础教程》笔记之抽象

《python基础教程》笔记之抽象

来源:芙姬情感网


创建函数

记录函数,在函数的开头写下字符串,它就会作为函数的一部分进行存储,这称为文档字符串,如

def square(x): 'Caculates the square of the number x.'
return x*x

>>> square.__doc__
'Caculates the square of the number x.'

help -- 在交互式解释器中使用会得到关于函数包括它的文档字符串的信息,如

>>> help(square)
Help on function square in module __main__:

square(x)
Caculates the square of the number x.

所有的函数都返回了东西:当不需要它们返回值的时候,它们就返回None。

参数魔法

显示全文