# specify a default value for one or more arguments. # This creates a function that can be called with fewer arguments than it is defined # to allow. For example: def ask_ok(prompt, retries=4, complaint='Yes or no, please!'): while True: ok = raw_input(prompt) if ok in ('y', 'ye', 'yes'): return True if ok in ('n', 'no', 'nop', 'nope'): return False retries = retries - 1 if retries < 0: raise IOError, 'refusenik user' print complaint #This function can be called either like this: ask_ok('Do you really want to quit?') # or like this: ask_ok('OK to overwrite the file?', 2)
收藏
0人收藏
- 2016-01-12 11:27:22Power function by Solon.Ring
- 2016-02-28 16:50:57Built-in function len() returns the length of a string by 蟋蟀MM
- 2016-03-14 15:24:29Define function in Lambda Forms by 风云轩
- 2016-03-26 17:47:12yield statement works with for loop by xwz
- 2016-04-23 14:00:04Do a map on list by jack.chen
- 2016-05-30 12:39:27Convert string to a list and add them together by 张宋付
- 2016-08-18 21:12:56Illustrate parameter passing: tuple, type and tuple by 山药
- 2016-08-19 11:43:26zfill(): pads a numeric string on the left with zeros by wubai
- 2016-10-30 09:03:05Printing ASCII by xwz
- 2016-12-25 13:37:02dir() does not list the names of built-in functions and variables by 司马
- 2017-03-06 09:26:45Generator Expressions by 山药
相关聚客文章
- Best non-cryptographic hashing function in Python
- Python笔记——数字类型的几个函数
- Function variations in Python
- Python的function和unbound/bound method
- Python function 学习笔记(1)
- Python学习笔记——可变对象和不可变对象
- 多进程socket共用
- Ken Thompson的经典命题:输出自身源代码的程序(c,python,java)
- 在创建list/tuple时多写一个逗号
- A Bite of Python
- PostgreSQL extend function - C example
- Python 不是 C