開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python 3.4 (プログラミング言語)
Learning Python (Mark Lutz (著)、Oreilly & Associates Inc)のPART Ⅱ.(Types and Operations)、Chapter 9.(Tuples, Files, and Everything Else)、Test Your Knowledge: Quiz 6.を解いてみる。
その他参考書籍
Test Your Knowledge: Quiz 6.
コード(BBEdit)
sample5.py
#!/usr/bin/env python3 #-*- coding: utf-8 -*- # 0, False, empty string, empty collection are False for x in [0, False, '', [], {}, ()]: if x: print('{0} is True.'.format(x)) else: print('{0} is False.'.format(x)) # other objects are True for x in [10, True, 'python', [1], {'a':1}, (0,)]: if x: print('{0} is True.'.format(x)) else: print('{0} is False.'.format(x))
入出力結果(Terminal, IPython)
$ ./sample6.py 0 is False. False is False. is False. [] is False. {} is False. () is False. 10 is True. True is True. python is True. [1] is True. {'a': 1} is True. (0,) is True. $
0 コメント:
コメントを投稿