创建函数
记录函数,在函数的开头写下字符串,它就会作为函数的一部分进行存储,这称为文档字符串,如
def square(x): 'Caculates the square of the number x.'
return x*x
>>> square.__doc__
'Caculates the square of the number x.'
help -- 在交互式解释器中使用会得到关于函数包括它的文档字符串的信息,如
立即学习“Python免费学习笔记(深入)”;
>>> help(square)
Help on function square in module __main__:
square(x)
Caculates the square of the number x.
所有的函数都返回了东西:当不需要它们返回值的时候,它们就返回None。
参数魔法
以上就是《python基础教程》笔记之抽象的内容,更多相关内容请关注PHP中文网(www.php.cn)!
python怎么学习?python怎么入门?python在哪学?python怎么学才快?不用担心,这里为大家提供了python速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号