加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python开发_python中的函数定义

发布时间:2020-12-17 00:18:40 所属栏目:Python 来源:网络整理
导读:下面是我做的几个用列: def_str = ( == ( x** a,b = 0,1 a (a,end= a,b = b,a + length > i ask_ok(prompt,retries=4,complaint= ok = ok ( , , ok ( , , , retries = retries - 1 retries IOError( == x = 3 y = 4 n = 2000 (x, ,y, ,x, , ( (getList([ ],

下面是我做的几个用列:

def_str = ( == ( x** a,b = 0,1 a < (a,end= a,b = b,a + length > i ask_ok(prompt,retries=4,complaint= ok = ok (,, ok (,,, retries = retries - 1 retries < IOError( == x = 3 y = 4 n = 2000 (x,,y,,x,, ( (getList([],-10 ask_ok()

运行效果:

Python 3.3.2 (v3.3.2:d047928ae3f6,May 16 2013,00:03:43) [MSC v.1600 32, >>> ================================ RESTART ================================ >>></span><span style="color: #0000ff;"&gt;def</span><span style="color: #000000;"&gt; 函数名称([参数1,参数2,参数3......]): 执行语句 如: </span><span style="color: #0000ff;"&gt;def</span><span style="color: #000000;"&gt; helloWorld(): </span><span style="color: #0000ff;"&gt;print</span>(<span style="color: #800000;"&gt;'</span><span style="color: #800000;"&gt;hello</span><span style="color: #800000;"&gt;'</span><span style="color: #000000;"&gt;) </span><span style="color: #0000ff;"&gt;if</span> <span style="color: #800080;"&gt;__name__</span> == <span style="color: #800000;"&gt;'</span><span style="color: #800000;"&gt;_main__</span><span style="color: #800000;"&gt;'</span><span style="color: #000000;"&gt;: helloWorld() 输出:hello

输出:hello
<span style="color: #008000;">#<span style="color: #008000;">###############################################
<span style="color: #000000;">
函数可以带参数和返回值,参数将按从左到右的匹配,
参数可设置默认值,当使用函数时没给相应的参数时,
会按照默认值进行赋值

</span><span style="color: #008000;"&gt;#</span><span style="color: #008000;"&gt;###############################################</span>

3 的 4 次方( 3 ** 4 ) = 81<span style="color: #000000;">
函数fib(n),当n = 2000<span style="color: #000000;">
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597<span style="color: #000000;">
你输入的长度小于0
y输出:hello
Yes <span style="color: #0000ff;">or<span style="color: #000000;"> no,please!
y
Yes <span style="color: #0000ff;">or<span style="color: #000000;"> no,please!
y
Traceback (most recent call last):
File <span style="color: #800000;">"<span style="color: #800000;">E:/Python33/python_workspace/test_function.py<span style="color: #800000;">",line 80,<span style="color: #0000ff;">in <span style="color: #000000;">
ask_ok(<span style="color: #800000;">'<span style="color: #800000;">y<span style="color: #800000;">'<span style="color: #000000;">)
File <span style="color: #800000;">"<span style="color: #800000;">E:/Python33/python_workspace/test_function.py<span style="color: #800000;">",line 69,<span style="color: #0000ff;">in<span style="color: #000000;"> ask_ok
<span style="color: #0000ff;">raise IOError(<span style="color: #800000;">'<span style="color: #800000;">refusenik user<span style="color: #800000;">'<span style="color: #000000;">)
OSError: refusenik user
>>>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读