Python入门的36个例子——17 Return
2009-09-12 01:32
423 查看
# 017 def lifeIsAMirror(): string = raw_input() if string == 'I love you!': return 'I love you, too!' elif string == 'Fuck you!': return '' else: return # end of def string = lifeIsAMirror() if len(string) == 0: print 'You have nothing.' else: print string # end of if
output:
1 2 3 4 5 6 | >>> Fuck you! You have nothing. >>> I love you! I love you, too! |
相关文章推荐
- Python入门的36个例子——01 我见过的最容易实现的“Hello World!”
- Python入门的36个例子——08 If —— 分叉语句
- Python入门的36个例子之16: 关键参数 —— 嘿!请把这个纸条给小强
- Python入门的36个例子 之 24 -> 再说说String
- Python入门的36个例子 之 32 -> OOP – Inheritance 继承
- Python入门的36个例子——02 Help! —— 如何获取帮助
- Python入门的36个例子——09 While —— 怎么老是你
- Python入门的36个例子 之 25 -> Console In File Out
- Python入门的36个例子 之 33 -> try – 异常是不可避免的,关键是怎样处理
- Python入门的36个例子——10 For —— “计数器”与“遍历器”
- Python入门的36个例子 之 18 -> Modules —— 将它们放到不同的文件里
- Python入门的36个例子 之 26 -> File In Console Out
- Python入门的36个例子 之 34 -> Raise An Error – 自定义异常信息
- Python入门的36个例子——03 Python 中的数“只有”四种类型
- Python入门的36个例子——11 Break —— 终结者
- Python入门的36个例子 之 19 -> List
- Python入门的36个例子 之 27 -> Add Something Into A File
- Python入门的36个例子 之 35 -> try – 一个使用的例子
- Python入门的36个例子——04 优雅的字符串
- Python入门的36个例子——12 Continue —— 路上的跳板(躲过一劫)