Practical Programming
An Introduction to Computer Science
Using Python 3
(Pragmatic Programmers)
(Pragmatic Bookshelf)
Paul Gries (著) Jennifer Campbell (著)
Jason Montojo (著) Lynn Beighley (編集)
開発環境
- OS X Mavericks - Apple(OS)
- Emacs (CUI)、BBEdit - Bare Bones Software, Inc. (GUI) (Text Editor)
- Python 3.4 (プログラミング言語)
Practical Programming: An Introduction to Computer Science Using Python 3 (Pragmatic Programmers) (Paul Gries (著)、Jennifer Campbell (著)、Jason Montojo (著)、Lynn Beighley (編集)、Pragmatic Bookshelf)のChapter 4(Working with Text)、4.7(Exercises) 4.を解いてみる。
4.7(Exercises) 4.
コード(BBEdit)
sample8.py
#!/usr/bin/env python3 #-*- coding: utf-8 -*- def square(num): return num * num if __name__ == '__main__': for num in range(10): print('square({0}) -> {1}'.format(num, square(num)))
入出力結果(Terminal, IPython)
$ ipython Python 3.4.1 (default, May 21 2014, 01:39:38) Type "copyright", "credits" or "license" for more information. IPython 2.1.0 -- An enhanced Interactive Python. ? -> Introduction and overview of IPython's features. %quickref -> Quick reference. help -> Python's own help system. object? -> Details about 'object', use 'object??' for extra details. In [1]: len('') Out[1]: 0 In [2]: len("") Out[2]: 0 In [3]: s = '' In [4]: len(s) Out[4]: 0 In [5]: s = "" In [6]: len(s) Out[6]: 0 In [7]: s = """""" In [8]: len(s) Out[8]: 0 In [9]: s = '''''' In [10]: len(s) Out[10]: 0 In [11]: quit() $
0 コメント:
コメントを投稿