python第16篇之关键参数赋值(keyword)
来源:互联网 发布:python的应用范围 编辑:程序博客网 时间:2024/05/18 16:16
#!/usr/bin/pythondef total(initial=5,*numbers,vegetables): count = initial for number in numbers: count += number count += vegetables return countprint(total(10,1,2,3,vegetables=50))print(total(10,1,2,30))
定义一个函数,调用了两次,第一次没有问题。
第二次调用就出现问题:
66Traceback (most recent call last): File "./9keywords.py", line 10, in <module> print(total(10,1,2,30))TypeError: total() missing 1 required keyword-only argument: 'vegetables'
原因时vegetables这个参数没有给值。这里的vegetables是一个key-word必须给一个值。
阅读全文
0 0
- python第16篇之关键参数赋值(keyword)
- python(第三天):Keyword-Only参数
- python关键参数
- stylus之关键字参数(Keyword Arguments)
- Python学习笔记--《简明Python教程》之默认函数参数和关键参数函数
- python关键参数测试结果
- Python 函数 参数 形式 Default Argument Keyword Arguments Formal Arguments
- python 函数默认参数值、关键参数
- Python入门的36个例子之16: 关键参数 —— 嘿!请把这个纸条给小强
- 《Python核心编程(第2版)》读书笔记(2)之赋值(关键词:Python/赋值/引用/传递)
- python builtin keyword: property
- python yield keyword
- python keyword模块解析
- Python-keyword-global & nonlocal
- python _缺省参数及赋值
- python第15篇之可变参数的函数的使用
- python之赋值与拷贝
- 关于python 的函数默认参数与关键字keyword的想法
- 【Lua】Mac系统下配置SublimeText的Lua编译环境
- 二叉树非递归遍历
- 异常 The content of the adapter has changed but ListView did not receive a notification可能的一种解决方法
- Vue.js系列之vue-resource
- 前端知识谱图
- python第16篇之关键参数赋值(keyword)
- ESP8266 sdk开发入门
- [笔记]: 背包问题
- 设计模式分类与六大原则
- springboot学习9之admin监控配置
- 20170613
- MFC使用TRACKMOUSEEVENT触发mouseHover和mouseLeave
- 3(3)、uboot根目录下的config.mk文件代码
- github上建一个自己常用的第三方插件