学习《Python基础教程(第二版)》笔记10--抽象3(练习)
来源:互联网 发布:清理软件残留 编辑:程序博客网 时间:2024/06/10 20:02
6.4.6 练习使用参数
1.
>>> def story(**kwds): #处理关键字参数。
... return 'once upon a time,there was a' '%(job)s called %(name)s.' %kwds
...
>>>
>>> story('nice','king') #要加上关键字参数才行。
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: story() takes exactly 0 arguments (2 given)
>>> story(job='nice',name='king') #不加print返回的字符串加上’ ’。
'once upon a time,there was anice called king.'
>>> print story(job='nice',name='king') #加上返回不加’ ’。
once upon a time,there was anice called king.
2. #在notepad++中编写代码不能调用.
>>> def interval(start, stop=None, step=1):
... 'imitates range() for step > 0'
... if stop is None:
... start,stop = 0, start
... result = []
... i = start
... while i < stop:
... result.append(i) #list末尾添加新的对象。
... i+=step
... return result
...
>>>
>>> interval(10)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
>>> interval(2,3,4)
[2]
>>> interval()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: interval() takes at least 1 argument (0 given)
>>> interval(0)
[]
- 学习《Python基础教程(第二版)》笔记10--抽象3(练习)
- 学习《Python基础教程(第二版)》笔记10--抽象2
- 学习《Python基础教程(第二版)》笔记9--抽象1
- *python基础教程(第二版)(学习笔记)*
- 《Python基础教程第二版》学习笔记(一)第一章 基础知识
- 学习《Python基础教程(第二版)》笔记1
- 学习《Python基础教程(第二版)》笔记2--基础知识
- 学习《Python基础教程(第二版)》笔记4---使用字符串
- 学习《Python基础教程(第二版)》笔记5---字典
- 第六章-抽象——python基础教程(第二版)笔记
- 第七章-更加抽象——python基础教程(第二版)笔记
- 学习笔记:《jQuery基础教程》第四版第二章课后练习
- 笔记-Python基础教程(第二版)第一章
- 学习《Python基础教程(第二版)》笔记3--列表和元组
- 《Python基础教程》学习笔记(6-7抽象)
- python基础教程_学习笔记9:抽象
- 《Python基础教程》学习笔记 Chp6 抽象
- 《Python基础教程》学习笔记 Chp7 更加抽象
- Eclipse项目代码上传到GitHub
- go后台和web编程
- MySQL基本操作示例
- 手动打包.a静态库
- ADT在eclipse中重装时的问题--Cannot complete the install because of a conflicting dependency
- 学习《Python基础教程(第二版)》笔记10--抽象3(练习)
- Spring 数据库处理Clob/Blob大对象
- 第七周项目1-点类-一般函数
- Bmob 后端云——史上最简单的登录
- scala学习
- 《程序员必读好书》
- 第七周项目1-成员函数,友元函数,一般函数有区别
- java面试题之 ((NULL)null).haha();
- qsort函数用法