请选择 进入手机版 | 继续访问电脑版
 找回密码
 立即注册
  • 便民服务
  • 关注我们
  • 社区新手
<article data-content="[{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;3060-1621846615933&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;p5PQ-1621846617594&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;函数好处&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quotaHk-1656051153192&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;WKZI-1656051153179&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;代码重复使用,保持一致性,易维护&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;u0b2-1656051487710&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;DF9e-1656051487708&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;zBGv-1656051488014&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;APJi-1656051488012&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;函数定义规则&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;X15u-1656051494684&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quotm5I-1656051494682&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;函数代码块以def  关键字开头&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;hO6N-1656051510469&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;er2R-1656051510468&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;后面接函数标识名称和小括号(),名称不能用纯数字或python保留字符进行定义&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;zlXr-1656051660562&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;ANpj-1656051660561&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;不要以文件名命名,不能出现特殊符号,简短且见名知意&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;WDzY-1656051789803&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;UyIT-1656051789788&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;057r-1656051791406&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;4tyR-1656051791404&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;def dcs():&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;f5JF-1656051805759&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{&quot;style&quot;:{&quot;textIndent&quot;:28}},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;NtWF-1656051805757&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;函数体&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;0Z9L-1656051895782&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{&quot;style&quot;:{&quot;textIndent&quot;:0}},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;8ypL-1656051895780&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;def  通过def  来定义函数,顶格写&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;umBk-1656051935611&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{&quot;style&quot;:{&quot;textIndent&quot;:0}},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;337X-1656051935596&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;def dcs():  定义了一个函数名称叫dcs 函数名称可以进行自定义&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;yV5c-1656052026001&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{&quot;style&quot;:{&quot;textIndent&quot;:0}},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;isoU-1656052025998&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;函数体  一个tab键也就是4个空格,函数体中就是代码块&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;YSDW-1656052451634&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{&quot;style&quot;:{}},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;FbUj-1656052451629&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;def dcs1(a,b):#定义函数&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;C13r-1656052452451&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{&quot;style&quot;:{&quot;textIndent&quot;:28},&quot;version&quot;:1},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;nyDI-1656052452450&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;print(a*b)#函数体&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;XRtz-1656052452453&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{&quot;style&quot;:{},&quot;version&quot;:1},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;QeZr-1656052452452&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;def dcs2(a,b):#定义函数&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;TK5X-1656052452455&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{&quot;style&quot;:{&quot;textIndent&quot;:28},&quot;version&quot;:1},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;DdSd-1656052452454&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;print(a+b)#函数体&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;kCJS-1656052452457&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{&quot;style&quot;:{},&quot;version&quot;:1},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;LIQZ-1656052452456&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;dcs1(2,5)#调用函数自己来得到函数中的结果&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;mAHK-1656052452459&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{&quot;style&quot;:{},&quot;version&quot;:1},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;88PI-1656052452458&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;dcs2(2,5)#调用函数自己来得到函数中的结果&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;TLbz-1656063334221&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{&quot;style&quot;:{},&quot;version&quot;:1},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;a5Zm-1656063334219&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;Yb3F-1656051654479&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;jUhC-1656051654463&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;def dcs3():\r&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;D3Xm-1656063330888&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{&quot;version&quot;:1},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;XiLe-1656063330889&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;    pass #占位符,函数体中一定要有值,没有则抛异常\r&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;ZlAA-1656063330890&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{&quot;version&quot;:1},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;AOrW-1656063330891&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;dcs3()#函数调用不受规则限制,在任务位置都可以调用&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;KTDQ-1656063337945&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{&quot;version&quot;:1},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;3lHc-1656063337943&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;9xT0-1656051510970&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;Cl4N-1656051510968&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;函数调用方式&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;wV0m-1656052974205&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;GFHJ-1656052974202&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;第一种&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;cHk0-1656052996501&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{&quot;style&quot;:{}},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;r2ur-1656052996499&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;def dcs4():&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;YMIr-1656052997807&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{&quot;style&quot;:{&quot;textIndent&quot;:28},&quot;version&quot;:1},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;4Syp-1656052997806&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;print(" dcs16')","marks":[]}]}],"state":{}},{"type":"block","id":"mzhh-1656052997809","name":"paragraph","data":{"style":{},"version":1},"nodes":[{"type":"text","id":"znj1-1656052997808","leaves":[{"text":"dcs4()","marks":[]}]}],"state":{}},{"type":"block","id":"2r8v-1656053189035","name":"paragraph","data":{"style":{},"version":1},"nodes":[{"type":"text","id":"trps-1656053189033","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"72mb-1656053182290","name":"paragraph","data":{"style":{},"version":1},"nodes":[{"type":"text","id":"uwl3-1656053182284","leaves":[{"text":"第二种="" 主函数","marks":[]}]}],"state":{}},{"type":"block","id":"5cxn-1656053192382","name":"paragraph","data":{"style":{},"version":1},"nodes":[{"type":"text","id":"pxdq-1656053192381","leaves":[{"text":"直接输入main="" 可以关联出来","marks":[]}]}],"state":{}},{"type":"block","id":"trcg-1656053212676","name":"paragraph","data":{"style":{},"version":1},"nodes":[{"type":"text","id":"shvg-1656053212674","leaves":[{"text":"def="" dcs4():","marks":[]}]}],"state":{}},{"type":"block","id":"ehcs-1656053230971","name":"paragraph","data":{"style":{"textindent":28},"version":1},"nodes":[{"type":"text","id":"23rk-1656053230970","leaves":[{"text":"print('dcs16')","marks":[]}]}],"state":{}},{"type":"block","id":"eiid-1656053230973","name":"paragraph","data":{"style":{},"version":1},"nodes":[{"type":"text","id":"zrkj-1656053230972","leaves":[{"text":"def="" dcs5():","marks":[]}]}],"state":{}},{"type":"block","id":"ynsz-1656053230975","name":"paragraph","data":{"style":{"textindent":28},"version":1},"nodes":[{"type":"text","id":"tca7-1656053230974","leaves":[{"text":"print('dcs17')","marks":[]}]}],"state":{}},{"type":"block","id":"5gnu-1656053230977","name":"paragraph","data":{"style":{},"version":1},"nodes":[{"type":"text","id":"nyy9-1656053230976","leaves":[{"text":"if="" __name","marks":[]},{"text":"__","marks":[{"type":"bold"}]},{"text":"="=" '__main","marks":[]},{"text":"__","marks":[{"type":"bold"}]},{"text":"':","marks":[]}]}],"state":{}},{"type":"block","id":"8mzx-1656053230979","name":"paragraph","data":{"style":{"textindent":28},"version":1},"nodes":[{"type":"text","id":"di6v-1656053230978","leaves":[{"text":"dcs4()","marks":[]}]}],"state":{}},{"type":"block","id":"tnua-1656053246961","name":"paragraph","data":{"style":{"textindent":28},"version":1},"nodes":[{"type":"text","id":"ivzc-1656053246959","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"t9dz-1656053247312","name":"paragraph","data":{"style":{"textindent":0},"version":1},"nodes":[{"type":"text","id":"qbxu-1656053247310","leaves":[{"text":"第三种="" 模块调用","marks":[]}]}],"state":{}},{"type":"block","id":"unrz-1656063376377","name":"paragraph","data":{"style":{},"version":1},"nodes":[{"type":"text","id":"dgav-1656063376362","leaves":[{"text":"def="" dcs1(a,b):#定义函数","marks":[]}]}],"state":{}},{"type":"block","id":"fftq-1656063376819","name":"paragraph","data":{"style":{"textindent":28},"version":1},"nodes":[{"type":"text","id":"sb4m-1656063376818","leaves":[{"text":"print(a*b)#函数体","marks":[]}]}],"state":{}},{"type":"block","id":"38w7-1656063376821","name":"paragraph","data":{"style":{},"version":1},"nodes":[{"type":"text","id":"yi6h-1656063376820","leaves":[{"text":"def="" dcs2(a,b):#定义函数","marks":[]}]}],"state":{}},{"type":"block","id":"ubke-1656063376823","name":"paragraph","data":{"style":{"textindent":28},"version":1},"nodes":[{"type":"text","id":"hnu1-1656063376822","leaves":[{"text":"print(a+b)#函数体","marks":[]}]}],"state":{}},{"type":"block","id":"ads6-1656063378884","name":"paragraph","data":{"style":{},"version":1},"nodes":[{"type":"text","id":"itgx-1656063378882","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"ozjd-1656053777524","name":"paragraph","data":{"style":{},"version":1},"nodes":[{"type":"text","id":"qoi0-1656053777519","leaves":[{"text":"from="" xiaozhang="" import="" hanshu","marks":[]}]}],"state":{}},{"type":"block","id":"qy7u-1656057314428","name":"paragraph","data":{"style":{},"version":1},"nodes":[{"type":"text","id":"pbqc-1656057314427","leaves":[{"text":"hanshu.dcs1(2,5)","marks":[]}]}],"state":{}},{"type":"block","id":"ppq5-1656057314430","name":"paragraph","data":{"style":{},"version":1},"nodes":[{"type":"text","id":"nmxt-1656057314429","leaves":[{"text":"hanshu.dcs2(2,5)","marks":[]}]}],"state":{}},{"type":"block","id":"t7nz-1656053777668","name":"paragraph","data":{"style":{"textindent":0},"version":1},"nodes":[{"type":"text","id":"kb7p-1656053777666","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"ckzz-1656051511069","name":"paragraph","data":{},"nodes":[{"type":"text","id":"ogpn-1656051511068","leaves":[{"text":"参数列表可以为空,即没有参数","marks":[]}]}],"state":{}},{"type":"block","id":"djrk-1656053813702","name":"paragraph","data":{},"nodes":[{"type":"text","id":"ty9a-1656053813687","leaves":[{"text":"也可以包含单个参数、多个参数、默认参数、可变长参数、参数之间使用逗号分隔","marks":[]}]}],"state":{}},{"type":"block","id":"dwes-1656053853310","name":"paragraph","data":{},"nodes":[{"type":"text","id":"srdb-1656053853296","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"8ka1-1656053854135","name":"paragraph","data":{},"nodes":[{"type":"text","id":"qawc-1656053854134","leaves":[{"text":"形参:写在函数声明的位置的变量","marks":[]}]}],"state":{}},{"type":"block","id":"etvr-1656053874248","name":"paragraph","data":{},"nodes":[{"type":"text","id":"mx8a-1656053874246","leaves":[{"text":"实参:在函数调用的时候给函数传递的值","marks":[]}]}],"state":{}},{"type":"block","id":"jg6v-1656053909400","name":"paragraph","data":{},"nodes":[{"type":"text","id":"gzen-1656053909385","leaves":[{"text":"传参:给函数传递信息的时候将实参交给形参的过程称为传参","marks":[]}]}],"state":{}},{"type":"block","id":"ci1n-1656057228597","name":"paragraph","data":{},"nodes":[{"type":"text","id":"o2wi-1656057228595","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"tv9p-1656051511170","name":"paragraph","data":{"style":{}},"nodes":[{"type":"text","id":"mh9c-1656051511169","leaves":[{"text":"函数中带有一个形参","marks":[]}]}],"state":{}},{"type":"block","id":"rqxl-1656057226838","name":"paragraph","data":{"style":{},"version":1},"nodes":[{"type":"text","id":"yo1j-1656057226836","leaves":[{"text":"def="" dcs(name):#定义函数包含一个形参","marks":[]}]}],"state":{}},{"type":"block","id":"zcdg-1656057226840","name":"paragraph","data":{"style":{"textindent":28},"version":1},"nodes":[{"type":"text","id":"4u9z-1656057226839","leaves":[{"text":"print(name)#打印形参","marks":[]}]}],"state":{}},{"type":"block","id":"vdgl-1656057226842","name":"paragraph","data":{"style":{},"version":1},"nodes":[{"type":"text","id":"gsqg-1656057226841","leaves":[{"text":"dcs('zhangsan')#函数调用并且传入实参","marks":[]}]}],"state":{}},{"type":"block","id":"wudy-1656057266472","name":"paragraph","data":{"style":{},"version":1},"nodes":[{"type":"text","id":"vf4a-1656057266469","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"cdpw-1656057226844","name":"paragraph","data":{"style":{},"version":1},"nodes":[{"type":"text","id":"obis-1656057226843","leaves":[{"text":"多个形参","marks":[]}]}],"state":{}},{"type":"block","id":"wivm-1656057226846","name":"paragraph","data":{"style":{},"version":1},"nodes":[{"type":"text","id":"7eed-1656057226845","leaves":[{"text":"def="" dcs1(name,age):#定义函数包含两个形参","marks":[]}]}],"state":{}},{"type":"block","id":"fwob-1656057226848","name":"paragraph","data":{"style":{"textindent":28},"version":1},"nodes":[{"type":"text","id":"zwoy-1656057226847","leaves":[{"text":"print(name,age)","marks":[]}]}],"state":{}},{"type":"block","id":"ywd5-1656057226850","name":"paragraph","data":{"style":{},"version":1},"nodes":[{"type":"text","id":"1tgw-1656057226849","leaves":[{"text":"dcs1('zhangsan',18)","marks":[]}]}],"state":{}},{"type":"block","id":"ayck-1656051511271","name":"paragraph","data":{},"nodes":[{"type":"text","id":"lr8d-1656051511269","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"gwjx-1656057233615","name":"paragraph","data":{},"nodes":[{"type":"text","id":"wch2-1656057233613","leaves":[{"text":"如果函数中有形参,函数调用的时候必须赋予实参,且实参个数一定是个形参对等","marks":[]}]}],"state":{}},{"type":"block","id":"cgcr-1656051511372","name":"paragraph","data":{},"nodes":[{"type":"text","id":"mvtx-1656051511371","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"txxq-1656051511472","name":"paragraph","data":{"style":{}},"nodes":[{"type":"text","id":"dd5y-1656051511471","leaves":[{"text":"带有默认参数","marks":[]}]}],"state":{}},{"type":"block","id":"grwt-1656057666625","name":"paragraph","data":{"style":{},"version":1},"nodes":[{"type":"text","id":"kbk5-1656057666624","leaves":[{"text":"def="" dcs(name="zhangsan" ):","marks":[]}]}],"state":{}},{"type":"block","id":"qguu-1656057666627","name":"paragraph","data":{"style":{"textindent":28},"version":1},"nodes":[{"type":"text","id":"xk7j-1656057666626","leaves":[{"text":"print(name)","marks":[]}]}],"state":{}},{"type":"block","id":"phee-1656057666629","name":"paragraph","data":{"style":{},"version":1},"nodes":[{"type":"text","id":"lawa-1656057666628","leaves":[{"text":"dcs()#调用函数未传实参","marks":[]}]}],"state":{}},{"type":"block","id":"zyia-1656057666631","name":"paragraph","data":{"style":{},"version":1},"nodes":[{"type":"text","id":"awma-1656057666630","leaves":[{"text":"dcs('lisi')#调用函数传入实参","marks":[]}]}],"state":{}},{"type":"block","id":"idft-1656057686383","name":"paragraph","data":{"style":{},"version":1},"nodes":[{"type":"text","id":"bbke-1656057686382","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"82ea-1656057688184","name":"paragraph","data":{"style":{},"version":1},"nodes":[{"type":"text","id":"pjpr-1656057688182","leaves":[{"text":"带有默认值的形参可以不赋予实参也可以赋予,赋予后会替换原本的默认值","marks":[]}]}],"state":{}},{"type":"block","id":"6zmk-1656051511573","name":"paragraph","data":{},"nodes":[{"type":"text","id":"vcbf-1656051511571","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"bkqi-1656051511673","name":"paragraph","data":{"style":{}},"nodes":[{"type":"text","id":"fsdd-1656051511671","leaves":[{"text":"带有默认值参数后面不能放形参","marks":[]}]}],"state":{}},{"type":"block","id":"kmsh-1656058000495","name":"paragraph","data":{"style":{},"version":1},"nodes":[{"type":"text","id":"cd79-1656058000494","leaves":[{"text":"def="" dcs(age,name="zhangsan" ):","marks":[]}]}],"state":{}},{"type":"block","id":"tg3u-1656058000498","name":"paragraph","data":{"style":{"textindent":28},"version":1},"nodes":[{"type":"text","id":"etde-1656058000496","leaves":[{"text":"print(name,age)","marks":[]}]}],"state":{}},{"type":"block","id":"ebh9-1656058000500","name":"paragraph","data":{"style":{},"version":1},"nodes":[{"type":"text","id":"ehzi-1656058000499","leaves":[{"text":"dcs(16)","marks":[]}]}],"state":{}},{"type":"block","id":"iwui-1656058005412","name":"paragraph","data":{"style":{},"version":1},"nodes":[{"type":"text","id":"cayw-1656058005410","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"fox6-1656058006768","name":"paragraph","data":{"style":{},"version":1},"nodes":[{"type":"text","id":"qute-1656058006766","leaves":[{"text":"没有带默认值的形参一定要放到带有默认值参数的前面","marks":[]}]}],"state":{}},{"type":"block","id":"lr1t-1656051511774","name":"paragraph","data":{},"nodes":[{"type":"text","id":"veyi-1656051511772","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"nbrm-1656051511874","name":"paragraph","data":{"style":{}},"nodes":[{"type":"text","id":"dguc-1656051511873","leaves":[{"text":"多个默认参数","marks":[]}]}],"state":{}},{"type":"block","id":"iayq-1656058166961","name":"paragraph","data":{"style":{},"version":1},"nodes":[{"type":"text","id":"nzfn-1656058166960","leaves":[{"text":"def="" dcs(age="18,name='zhangsan'):&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;Wpvz-1656058166963&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{&quot;style&quot;:{&quot;textIndent&quot;:28},&quot;version&quot;:1},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;BYIU-1656058166962&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;print(name,age)&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quotVUs-1656058166965&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{&quot;style&quot;:{},&quot;version&quot;:1},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;SZAn-1656058166964&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;dcs()&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;UlTB-1656058166967&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{&quot;style&quot;:{},&quot;version&quot;:1},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;7I2m-1656058166966&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;dcs(16,'lisi')&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;aLN0-1656051511975&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;Df0b-1656051511973&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;zN8P-1656058246341&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;S3mm-1656058246339&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;可变长元组和可变长字典&quot;,&quot;marks&quot;:[]}]}],&quot;state&quot;:{}},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;NYvt-1656058258245&quot;,&quot;name&quot;:&quot;paragraph&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quot;vygH-1656058258243&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;可变长元组:*" 一个星号来表示","marks":[]}]}],"state":{}},{"type":"block","id":"5guv-1656058279542","name":"paragraph","data":{},"nodes":[{"type":"text","id":"lph5-1656058279540","leaves":[{"text":"可变长字典:**="" 两个星号来表示","marks":[]}]}],"state":{}},{"type":"block","id":"mnhb-1656059833781","name":"paragraph","data":{},"nodes":[{"type":"text","id":"3mei-1656059833779","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"ubdr-1656059834415","name":"paragraph","data":{},"nodes":[{"type":"text","id":"lptl-1656059834413","leaves":[{"text":"可变长元组","marks":[]}]}],"state":{}},{"type":"block","id":"wjpn-1656058820186","name":"code","data":{"language":"","theme":"default","version":1,"wrap":false},"nodes":[{"type":"block","id":"oofa-1656058820177","name":"code-line","data":{},"nodes":[{"type":"text","id":"hwfw-1656058820176","leaves":[{"text":"def="" dcs(*name):#把name这个形参变为可变长元组类型","marks":[]}]}]},{"type":"block","id":"g7o7-1656058820179","name":"code-line","data":{},"nodes":[{"type":"text","id":"ece5-1656058820178","leaves":[{"text":"="" print(type(name))","marks":[]}]}]},{"type":"block","id":"5d6u-1656058820181","name":"code-line","data":{},"nodes":[{"type":"text","id":"n1v2-1656058820180","leaves":[{"text":"="" print(name)","marks":[]}]}]},{"type":"block","id":"vsex-1656058820183","name":"code-line","data":{},"nodes":[{"type":"text","id":"nrqu-1656058820182","leaves":[{"text":"dcs()#可变类型可以赋予实参,也可以不赋予实参","marks":[]}]}]},{"type":"block","id":"lw3c-1656058820185","name":"code-line","data":{},"nodes":[{"type":"text","id":"zwtv-1656058820184","leaves":[{"text":"dcs(1,2,3)#可变类型可以赋予多个实参","marks":[]}]}]}],"state":{}},{"type":"block","id":"umqk-1656059132063","name":"code","data":{"language":"","theme":"default","version":1},"nodes":[{"type":"block","id":"fwsr-1656059132055","name":"code-line","data":{},"nodes":[{"type":"text","id":"wavt-1656059132054","leaves":[{"text":"#可变长类型后面不能接普通形参","marks":[]}]}]},{"type":"block","id":"snvz-1656059132058","name":"code-line","data":{},"nodes":[{"type":"text","id":"umfl-1656059132057","leaves":[{"text":"def="" dcs(*name,age):","marks":[]}]}]},{"type":"block","id":"osvg-1656059132060","name":"code-line","data":{},"nodes":[{"type":"text","id":"4gyk-1656059132059","leaves":[{"text":"="" print(name,age)","marks":[]}]}]},{"type":"block","id":"lzds-1656059132062","name":"code-line","data":{},"nodes":[{"type":"text","id":"huxb-1656059132061","leaves":[{"text":"dcs('zhangsan',16)#报异常,因为age没有拿到实参","marks":[]}]}]}],"state":{}},{"type":"block","id":"bmxh-1656059289515","name":"code","data":{"language":"","theme":"default","version":1},"nodes":[{"type":"block","id":"464e-1656059289508","name":"code-line","data":{},"nodes":[{"type":"text","id":"fell-1656059289507","leaves":[{"text":"#普通形参一定要放到可变长类型的前面","marks":[]}]}]},{"type":"block","id":"irjd-1656059289510","name":"code-line","data":{},"nodes":[{"type":"text","id":"odul-1656059289509","leaves":[{"text":"def="" dcs(age,*name):","marks":[]}]}]},{"type":"block","id":"iu45-1656059289512","name":"code-line","data":{},"nodes":[{"type":"text","id":"94zr-1656059289511","leaves":[{"text":"="" print(name,="" age)","marks":[]}]}]},{"type":"block","id":"zpc2-1656059289514","name":"code-line","data":{},"nodes":[{"type":"text","id":"lfkj-1656059289513","leaves":[{"text":"dcs(16,18,112,'zhangsan')","marks":[]}]}]}],"state":{}},{"type":"block","id":"skn3-1656059507377","name":"code","data":{"language":"","theme":"default","version":1},"nodes":[{"type":"block","id":"bebc-1656059507370","name":"code-line","data":{},"nodes":[{"type":"text","id":"kbkg-1656059507369","leaves":[{"text":"#可变长类型后面一定接的是默认值参数","marks":[]}]}]},{"type":"block","id":"cplc-1656059507372","name":"code-line","data":{},"nodes":[{"type":"text","id":"sr60-1656059507371","leaves":[{"text":"def="" dcs(*name,age="24):&quot;,&quot;marks&quot;:[]}]}]},{&quot;type&quot;:&quot;block&quot;,&quot;id&quot;:&quot;wlzi-1656059507374&quot;,&quot;name&quot;:&quot;code-line&quot;,&quot;data&quot;:{},&quot;nodes&quot;:[{&quot;type&quot;:&quot;text&quot;,&quot;id&quot;:&quotfru-1656059507373&quot;,&quot;leaves&quot;:[{&quot;text&quot;:&quot;" print(name,age)","marks":[]}]}]},{"type":"block","id":"s6nf-1656059507376","name":"code-line","data":{},"nodes":[{"type":"text","id":"xhce-1656059507375","leaves":[{"text":"dcs('zhangsan',18,19,20)","marks":[]}]}]}],"state":{}},{"type":"block","id":"2zdh-1656059824616","name":"paragraph","data":{},"nodes":[{"type":"text","id":"yqil-1656059824618","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"y53m-1656059825986","name":"paragraph","data":{},"nodes":[{"type":"text","id":"theh-1656059825983","leaves":[{"text":"可变长字典","marks":[]}]}],"state":{}},{"type":"block","id":"vatv-1656059780300","name":"code","data":{"language":"","theme":"default","version":1},"nodes":[{"type":"block","id":"8bjh-1656059780293","name":"code-line","data":{},"nodes":[{"type":"text","id":"o3fw-1656059780291","leaves":[{"text":"def="" dcs(**name):#定义一个函数,函数中有可变长字典","marks":[]}]}]},{"type":"block","id":"m8eb-1656059780295","name":"code-line","data":{},"nodes":[{"type":"text","id":"tcta-1656059780294","leaves":[{"text":"="" print(type(name))#","marks":[]}]}]},{"type":"block","id":"sTVu-1656059780297","name":"code-line","data":{},"nodes":[{"type":"text","id":"Sefk-1656059780296","leaves":[{"text":"    print(name)#{}","marks":[]}]}]},{"type":"block","id":"3I1l-1656059780299","name":"code-line","data":{},"nodes":[{"type":"text","id":"tONt-1656059780298","leaves":[{"text":"dcs()#可变类型在调用函数是可以不赋予实参","marks":[]}]}]}],"state":{}},{"type":"block","id":"DX8G-1656051512647","name":"paragraph","data":{},"nodes":[{"type":"text","id":"QWlQ-1656051512645","leaves":[{"text":"可变长字典类型后不能带普通形参","marks":[]}]}],"state":{}},{"type":"block","id":"aDNH-1656051512748","name":"paragraph","data":{},"nodes":[{"type":"text","id":"B1RT-1656051512746","leaves":[{"text":"可变长元组不能再放在可变长字典后面","marks":[]}]}],"state":{}},{"type":"block","id":"dY1Z-1656060313142","name":"code","data":{"language":"","theme":"default","version":1},"nodes":[{"type":"block","id":"pQOu-1656060313135","name":"code-line","data":{},"nodes":[{"type":"text","id":"nXex-1656060313134","leaves":[{"text":"def dcs(*age,**name):","marks":[]}]}]},{"type":"block","id":"LTjR-1656060313137","name":"code-line","data":{},"nodes":[{"type":"text","id":"nFDH-1656060313136","leaves":[{"text":"    #可变长元组和字典同时存在只能将元组放在字典的前面","marks":[]}]}]},{"type":"block","id":"GLA1-1656060313139","name":"code-line","data":{},"nodes":[{"type":"text","id":"3Ue9-1656060313138","leaves":[{"text":"    print(name,age)","marks":[]}]}]},{"type":"block","id":"aGqp-1656060313141","name":"code-line","data":{},"nodes":[{"type":"text","id":"Z1xc-1656060313140","leaves":[{"text":"dcs(1,2,3,4,5,name='zhangsan')#{'name': 'zhangsan'} (1, 2, 3, 4, 5)","marks":[]}]}]}],"state":{}},{"type":"block","id":"daKf-1656051512950","name":"paragraph","data":{},"nodes":[{"type":"text","id":"JG4w-1656051512948","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"FqdW-1656051513050","name":"paragraph","data":{},"nodes":[{"type":"text","id":"T61O-1656051513048","leaves":[{"text":"全局变量和局部变量","marks":[]}]}],"state":{}},{"type":"block","id":"y8Pp-1656060704782","name":"code","data":{"language":"","theme":"default","version":1},"nodes":[{"type":"block","id":"lnT4-1656060704768","name":"code-line","data":{},"nodes":[{"type":"text","id":"qTAg-1656060704767","leaves":[{"text":"a=200#全局变量","marks":[]}]}]},{"type":"block","id":"iTve-1656060704771","name":"code-line","data":{},"nodes":[{"type":"text","id":"FXp3-1656060704770","leaves":[{"text":"def dcs():#定义函数","marks":[]}]}]},{"type":"block","id":"g0NH-1656060704773","name":"code-line","data":{},"nodes":[{"type":"text","id":"y3NX-1656060704772","leaves":[{"text":"    a=100#局部变量","marks":[]}]}]},{"type":"block","id":"Jw8z-1656060704775","name":"code-line","data":{},"nodes":[{"type":"text","id":"L9pC-1656060704774","leaves":[{"text":"    print(a)#打印的局部变量100","marks":[]}]}]},{"type":"block","id":"4Mn9-1656060704777","name":"code-line","data":{},"nodes":[{"type":"text","id":"HBFq-1656060704776","leaves":[{"text":"dcs()","marks":[]}]}]},{"type":"block","id":"Qnd1-1656060704779","name":"code-line","data":{},"nodes":[{"type":"text","id":"nflx-1656060704778","leaves":[{"text":"print(a)#打印全局变量200","marks":[]}]}]},{"type":"block","id":"1qXx-1656060704781","name":"code-line","data":{},"nodes":[{"type":"text","id":"6kvj-1656060704780","leaves":[{"text":"","marks":[]}]}]}],"state":{}},{"type":"block","id":"XD8V-1656051513251","name":"paragraph","data":{},"nodes":[{"type":"text","id":"5nL3-1656051513249","leaves":[{"text":"函数体中有变量则优先引用函数中的变量","marks":[]}]}],"state":{}},{"type":"block","id":"D1ys-1656060847841","name":"paragraph","data":{},"nodes":[{"type":"text","id":"g6nb-1656060847822","leaves":[{"text":"如果函数体中没有变量则引用函数体外的全局变量","marks":[]}]}],"state":{}},{"type":"block","id":"csDp-1656060877763","name":"paragraph","data":{},"nodes":[{"type":"text","id":"S5r2-1656060877746","leaves":[{"text":"全局变量可以被任何函数方法引用","marks":[]}]}],"state":{}},{"type":"block","id":"fqrn-1656063494607","name":"paragraph","data":{"style":{}},"nodes":[{"type":"text","id":"KVHJ-1656063494600","leaves":[{"text":"局部变量只能被当前函数本身来引用(如需要用可以用函数传递)","marks":[]}]}],"state":{}},{"type":"block","id":"ARN6-1656051513351","name":"paragraph","data":{},"nodes":[{"type":"text","id":"X2am-1656051513350","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"tAQ2-1656051513452","name":"paragraph","data":{},"nodes":[{"type":"text","id":"Wedm-1656051513450","leaves":[{"text":"把局部变量变为全局变量","marks":[]}]}],"state":{}},{"type":"block","id":"DUMU-1656061442882","name":"code","data":{"language":"","theme":"default","version":1},"nodes":[{"type":"block","id":"3Z4W-1656061442858","name":"code-line","data":{},"nodes":[{"type":"text","id":"Q6Ch-1656061442857","leaves":[{"text":"","marks":[]}]}]},{"type":"block","id":"Q3Mb-1656061442860","name":"code-line","data":{},"nodes":[{"type":"text","id":"jMBr-1656061442859","leaves":[{"text":"a=200#全局变量","marks":[]}]}]},{"type":"block","id":"QkUt-1656061442862","name":"code-line","data":{},"nodes":[{"type":"text","id":"Zt5f-1656061442861","leaves":[{"text":"def dcs1():#定义函数","marks":[]}]}]},{"type":"block","id":"IVdh-1656061442864","name":"code-line","data":{},"nodes":[{"type":"text","id":"CUPV-1656061442863","leaves":[{"text":"    global a #把函数中的局部变量声明为全局变量","marks":[]}]}]},{"type":"block","id":"c0yR-1656061442866","name":"code-line","data":{},"nodes":[{"type":"text","id":"feq0-1656061442865","leaves":[{"text":"    a=100#局部变量","marks":[]}]}]},{"type":"block","id":"suxf-1656061442868","name":"code-line","data":{},"nodes":[{"type":"text","id":"tG0N-1656061442867","leaves":[{"text":"    print(a)","marks":[]}]}]},{"type":"block","id":"bJ8k-1656061442871","name":"code-line","data":{},"nodes":[{"type":"text","id":"MCqK-1656061442869","leaves":[{"text":"dcs1()","marks":[]}]}]},{"type":"block","id":"IJzM-1656061442873","name":"code-line","data":{},"nodes":[{"type":"text","id":"vKe-1656061442872","leaves":[{"text":"print(a)","marks":[]}]}]},{"type":"block","id":"YqkS-1656061442875","name":"code-line","data":{},"nodes":[{"type":"text","id":"gRq0-1656061442874","leaves":[{"text":"","marks":[]}]}]},{"type":"block","id":"leY-1656061442877","name":"code-line","data":{},"nodes":[{"type":"text","id":"SoS8-1656061442876","leaves":[{"text":"def dcs2():#定义函数","marks":[]}]}]},{"type":"block","id":"nrZd-1656061442879","name":"code-line","data":{},"nodes":[{"type":"text","id":"IbUb-1656061442878","leaves":[{"text":"    print(a)","marks":[]}]}]},{"type":"block","id":"qyzX-1656061442881","name":"code-line","data":{},"nodes":[{"type":"text","id":"2HeZ-1656061442880","leaves":[{"text":"dcs2()#100","marks":[]}]}]}],"state":{}},{"type":"block","id":"k3ht-1656051513653","name":"paragraph","data":{},"nodes":[{"type":"text","id":"hEqf-1656051513652","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"ZliS-1656051513755","name":"paragraph","data":{},"nodes":[{"type":"text","id":"m3Pr-1656051513753","leaves":[{"text":"函数传递","marks":[]}]}],"state":{}},{"type":"block","id":"FKkK-1656061667541","name":"paragraph","data":{},"nodes":[{"type":"text","id":"x0Mm-1656061667538","leaves":[{"text":"return 语句","marks":[]}]}],"state":{}},{"type":"block","id":"rnxx-1656062487329","name":"code","data":{"language":"","theme":"default","version":1},"nodes":[{"type":"block","id":"snY3-1656062487305","name":"code-line","data":{},"nodes":[{"type":"text","id":"umTd-1656062487304","leaves":[{"text":"def dcs1():#定义函数","marks":[]}]}]},{"type":"block","id":"0Ns2-1656062487307","name":"code-line","data":{},"nodes":[{"type":"text","id":"D4P1-1656062487306","leaves":[{"text":"    a=100#局部变量","marks":[]}]}]},{"type":"block","id":"sAvD-1656062487309","name":"code-line","data":{},"nodes":[{"type":"text","id":"B2Ck-1656062487308","leaves":[{"text":"    return a #返回值,把一个具体的结果赋予给函数就需要用到此方法","marks":[]}]}]},{"type":"block","id":"K5AP-1656062487311","name":"code-line","data":{},"nodes":[{"type":"text","id":"wOD3-1656062487310","leaves":[{"text":"","marks":[]}]}]},{"type":"block","id":"mKne-1656062487313","name":"code-line","data":{},"nodes":[{"type":"text","id":"94BC-1656062487312","leaves":[{"text":"def dcs2():#定义函数","marks":[]}]}]},{"type":"block","id":"c4HY-1656062487315","name":"code-line","data":{},"nodes":[{"type":"text","id":"9K4K-1656062487314","leaves":[{"text":"    # a=dcs1()#第一种函数传递方式","marks":[]}]}]},{"type":"block","id":"ar18-1656062487317","name":"code-line","data":{},"nodes":[{"type":"text","id":"QYka-1656062487316","leaves":[{"text":"    c=50#局部变量","marks":[]}]}]},{"type":"block","id":"xjW2-1656062487319","name":"code-line","data":{},"nodes":[{"type":"text","id":"K123-1656062487318","leaves":[{"text":"    # c +=a","marks":[]}]}]},{"type":"block","id":"FWoI-1656062487321","name":"code-line","data":{},"nodes":[{"type":"text","id":"ai89-1656062487320","leaves":[{"text":"    c+=dcs1()#第二种函数传递方式","marks":[]}]}]},{"type":"block","id":"ZqdK-1656062487324","name":"code-line","data":{},"nodes":[{"type":"text","id":"nQVf-1656062487323","leaves":[{"text":"    print(c)","marks":[]}]}]},{"type":"block","id":"nD0X-1656062487326","name":"code-line","data":{},"nodes":[{"type":"text","id":"ECVM-1656062487325","leaves":[{"text":"dcs2()","marks":[]}]}]},{"type":"block","id":"qrQX-1656062487328","name":"code-line","data":{},"nodes":[{"type":"text","id":"iysu-1656062487327","leaves":[{"text":"","marks":[]}]}]}],"state":{}},{"type":"block","id":"rdub-1656063546407","name":"code","data":{"language":"","theme":"default","version":1},"nodes":[{"type":"block","id":"4cnP-1656063546387","name":"code-line","data":{},"nodes":[{"type":"text","id":"qC0C-1656063546386","leaves":[{"text":"def dcs1(): #定义函数","marks":[]}]}]},{"type":"block","id":"UhRF-1656063546389","name":"code-line","data":{},"nodes":[{"type":"text","id":"rwZO-1656063546388","leaves":[{"text":"    a=100 #局部变量","marks":[]}]}]},{"type":"block","id":"HjOP-1656063546391","name":"code-line","data":{},"nodes":[{"type":"text","id":"IpOA-1656063546390","leaves":[{"text":"    c=a/2 #除法","marks":[]}]}]},{"type":"block","id":"EMi9-1656063546393","name":"code-line","data":{},"nodes":[{"type":"text","id":"SvFx-1656063546392","leaves":[{"text":"    return c #返回值","marks":[]}]}]},{"type":"block","id":"8R1p-1656063546395","name":"code-line","data":{},"nodes":[{"type":"text","id":"VSdx-1656063546394","leaves":[{"text":"","marks":[]}]}]},{"type":"block","id":"GShj-1656063546397","name":"code-line","data":{},"nodes":[{"type":"text","id":"H8vE-1656063546396","leaves":[{"text":"def dcs2(): #定义函数","marks":[]}]}]},{"type":"block","id":"gFTi-1656063546399","name":"code-line","data":{},"nodes":[{"type":"text","id":"Hn7d-1656063546398","leaves":[{"text":"    d=dcs1() #函数传递","marks":[]}]}]},{"type":"block","id":"0QFo-1656063546401","name":"code-line","data":{},"nodes":[{"type":"text","id":"q8QW-1656063546400","leaves":[{"text":"    d*=2 #乘法","marks":[]}]}]},{"type":"block","id":"7MhF-1656063546404","name":"code-line","data":{},"nodes":[{"type":"text","id":"SgcV-1656063546403","leaves":[{"text":"    return d","marks":[]}]}]},{"type":"block","id":"AuA0-1656063546406","name":"code-line","data":{},"nodes":[{"type":"text","id":"7W1M-1656063546405","leaves":[{"text":"print(dcs2())","marks":[]}]}]}],"state":{}},{"type":"block","id":"ioRE-1656051514057","name":"paragraph","data":{},"nodes":[{"type":"text","id":"MM71-1656051514055","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"NpW9-1656051514157","name":"paragraph","data":{},"nodes":[{"type":"text","id":"KzOO-1656051514156","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"Dof6-1656051514258","name":"paragraph","data":{},"nodes":[{"type":"text","id":"5zzV-1656051514256","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"cRXg-1656051514359","name":"paragraph","data":{},"nodes":[{"type":"text","id":"LQ9D-1656051514357","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"hhKT-1656051514458","name":"paragraph","data":{},"nodes":[{"type":"text","id":"rjtm-1656051514457","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"wp8g-1656051514559","name":"paragraph","data":{},"nodes":[{"type":"text","id":"wIjy-1656051514557","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"d2fh-1656051514661","name":"paragraph","data":{},"nodes":[{"type":"text","id":"YKKb-1656051514659","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"wxBm-1656051514761","name":"paragraph","data":{},"nodes":[{"type":"text","id":"ZcrX-1656051514759","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"rIqT-1656051514862","name":"paragraph","data":{},"nodes":[{"type":"text","id":"5Lmz-1656051514860","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"4Otf-1656051514962","name":"paragraph","data":{},"nodes":[{"type":"text","id":"bKP7-1656051514960","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"bOVW-1656051515062","name":"paragraph","data":{},"nodes":[{"type":"text","id":"gGIL-1656051515061","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"x7v3-1656051515163","name":"paragraph","data":{},"nodes":[{"type":"text","id":"S81y-1656051515162","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"QKLl-1656051515264","name":"paragraph","data":{},"nodes":[{"type":"text","id":"9Eww-1656051515262","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"5cNl-1656051515366","name":"paragraph","data":{},"nodes":[{"type":"text","id":"BHez-1656051515364","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"baCl-1656051515466","name":"paragraph","data":{},"nodes":[{"type":"text","id":"cfkT-1656051515465","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"Fv82-1656051515567","name":"paragraph","data":{},"nodes":[{"type":"text","id":"6knZ-1656051515564","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"rY4B-1656051515667","name":"paragraph","data":{},"nodes":[{"type":"text","id":"DO1h-1656051515666","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"XNTo-1656051515768","name":"paragraph","data":{},"nodes":[{"type":"text","id":"tZMV-1656051515767","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"jV7e-1656051515868","name":"paragraph","data":{},"nodes":[{"type":"text","id":"K2ye-1656051515866","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"BLaX-1656051515969","name":"paragraph","data":{},"nodes":[{"type":"text","id":"4kmy-1656051515967","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"RCze-1656051516069","name":"paragraph","data":{},"nodes":[{"type":"text","id":"3j7L-1656051516068","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"hNcl-1656051516170","name":"paragraph","data":{},"nodes":[{"type":"text","id":"9FZ7-1656051516168","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"AeMX-1656051516271","name":"paragraph","data":{},"nodes":[{"type":"text","id":"FUgO-1656051516269","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"iWuM-1656051516372","name":"paragraph","data":{},"nodes":[{"type":"text","id":"tBel-1656051516370","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"ZO2y-1656051516471","name":"paragraph","data":{},"nodes":[{"type":"text","id":"An18-1656051516470","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"aRA-1656051516573","name":"paragraph","data":{},"nodes":[{"type":"text","id":"fDot-1656051516571","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"X78k-1656051516675","name":"paragraph","data":{},"nodes":[{"type":"text","id":"84wE-1656051516673","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"rXHS-1656051516774","name":"paragraph","data":{},"nodes":[{"type":"text","id":"ju5T-1656051516772","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"rA1m-1656051516875","name":"paragraph","data":{},"nodes":[{"type":"text","id":"rXJh-1656051516873","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"Bt5-1656051516976","name":"paragraph","data":{},"nodes":[{"type":"text","id":"NdAW-1656051516975","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"iXU-1656051517076","name":"paragraph","data":{},"nodes":[{"type":"text","id":"Lwmp-1656051517074","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"Fsxx-1656051517177","name":"paragraph","data":{},"nodes":[{"type":"text","id":"q5e5-1656051517175","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"UGnD-1656051517277","name":"paragraph","data":{},"nodes":[{"type":"text","id":"K9Ke-1656051517275","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"H8z0-1656051473381","name":"paragraph","data":{},"nodes":[{"type":"text","id":"tkJD-1656051473378","leaves":[{"text":"","marks":[]}]}],"state":{}},{"type":"block","id":"Llp2-1656051473561","name":"paragraph","data":{},"nodes":[{"type":"text","id":"nJsB-1656051473559","leaves":[{"text":"","marks":[]}]}],"state":{}}]'>函数好处
代码重复使用,保持一致性,易维护

函数定义规则
函数代码块以def  关键字开头
后面接函数标识名称和小括号(),名称不能用纯数字或python保留字符进行定义
不要以文件名命名,不能出现特殊符号,简短且见名知意

def dcs():
函数体
def  通过def  来定义函数,顶格写
def dcs():  定义了一个函数名称叫dcs 函数名称可以进行自定义
函数体  一个tab键也就是4个空格,函数体中就是代码块
def dcs1(a,b):#定义函数
print(a*b)#函数体
def dcs2(a,b):#定义函数
print(a+b)#函数体
dcs1(2,5)#调用函数自己来得到函数中的结果
dcs2(2,5)#调用函数自己来得到函数中的结果

def dcs3():
    pass #占位符,函数体中一定要有值,没有则抛异常
dcs3()#函数调用不受规则限制,在任务位置都可以调用

函数调用方式
第一种
def dcs4():
print('dcs16')
dcs4()

第二种     主函数
直接输入main  可以关联出来
def dcs4():
print('dcs16')
def dcs5():
print('dcs17')
if __name__ == '__main__':
dcs4()

第三种   模块调用
def dcs1(a,b):#定义函数
print(a*b)#函数体
def dcs2(a,b):#定义函数
print(a+b)#函数体

from xiaozhang import hanshu
hanshu.dcs1(2,5)
hanshu.dcs2(2,5)

参数列表可以为空,即没有参数
也可以包含单个参数、多个参数、默认参数、可变长参数、参数之间使用逗号分隔

形参:写在函数声明的位置的变量
实参:在函数调用的时候给函数传递的值
传参:给函数传递信息的时候将实参交给形参的过程称为传参

函数中带有一个形参
def dcs(name):#定义函数包含一个形参
print(name)#打印形参
dcs('zhangsan')#函数调用并且传入实参

多个形参
def dcs1(name,age):#定义函数包含两个形参
print(name,age)
dcs1('zhangsan',18)

如果函数中有形参,函数调用的时候必须赋予实参,且实参个数一定是个形参对等

带有默认参数
def dcs(name='zhangsan'):
print(name)
dcs()#调用函数未传实参
dcs('lisi')#调用函数传入实参

带有默认值的形参可以不赋予实参也可以赋予,赋予后会替换原本的默认值

带有默认值参数后面不能放形参
def dcs(age,name='zhangsan'):
print(name,age)
dcs(16)

没有带默认值的形参一定要放到带有默认值参数的前面

多个默认参数
def dcs(age=18,name='zhangsan'):
print(name,age)
dcs()
dcs(16,'lisi')

可变长元组和可变长字典
可变长元组:*  一个星号来表示
可变长字典:**  两个星号来表示

可变长元组
def dcs(*name):#把name这个形参变为可变长元组类型    print(type(name))    print(name)dcs()#可变类型可以赋予实参,也可以不赋予实参dcs(1,2,3)#可变类型可以赋予多个实参
#可变长类型后面不能接普通形参def dcs(*name,age):    print(name,age)dcs('zhangsan',16)#报异常,因为age没有拿到实参
#普通形参一定要放到可变长类型的前面def dcs(age,*name):    print(name, age)dcs(16,18,112,'zhangsan')
#可变长类型后面一定接的是默认值参数def dcs(*name,age=24):    print(name,age)dcs('zhangsan',18,19,20)

可变长字典
def dcs(**name):#定义一个函数,函数中有可变长字典    print(type(name))#<class 'dict'>    print(name)#{}dcs()#可变类型在调用函数是可以不赋予实参
可变长字典类型后不能带普通形参
可变长元组不能再放在可变长字典后面
def dcs(*age,**name):    #可变长元组和字典同时存在只能将元组放在字典的前面    print(name,age)dcs(1,2,3,4,5,name='zhangsan')#{'name': 'zhangsan'} (1, 2, 3, 4, 5)

全局变量和局部变量
a=200#全局变量def dcs():#定义函数    a=100#局部变量    print(a)#打印的局部变量100dcs()print(a)#打印全局变量200
函数体中有变量则优先引用函数中的变量
如果函数体中没有变量则引用函数体外的全局变量
全局变量可以被任何函数方法引用
局部变量只能被当前函数本身来引用(如需要用可以用函数传递)

把局部变量变为全局变量
a=200#全局变量def dcs1():#定义函数    global a #把函数中的局部变量声明为全局变量    a=100#局部变量    print(a)dcs1()print(a)def dcs2():#定义函数    print(a)dcs2()#100

函数传递
return 语句
def dcs1():#定义函数    a=100#局部变量    return a #返回值,把一个具体的结果赋予给函数就需要用到此方法def dcs2():#定义函数    # a=dcs1()#第一种函数传递方式    c=50#局部变量    # c +=a    c+=dcs1()#第二种函数传递方式    print(c)dcs2()
def dcs1(): #定义函数    a=100 #局部变量    c=a/2 #除法    return c #返回值def dcs2(): #定义函数    d=dcs1() #函数传递    d*=2 #乘法    return dprint(dcs2())





































分享至 : QQ空间
收藏
腹中有书气自华,圣贤为友品自高

0 个回复

您需要登录后才可以回帖 登录 | 立即注册