開発環境
- 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 Ⅲ.(Statements and Syntax)、Test Your Knowledge: Part Ⅲ Exercises、1-a, b, c.(Coding basic loops)を解いてみる。
その他参考書籍
- Pythonチュートリアル 第2版
- Python クックブック 第2版 (原書(最新版))
- Programming Python
- Python Pocket Reference (Pocket Reference (O'Reilly))
1-a, b, c.(Coding basic loops)
コード(BBEdit)
sample1.py
#!/usr/bin/env python3
#-*- coding: utf-8 -*-
print('a.')
s = 'pythob'
for ch in s:
print(ord(ch))
print('b.')
n = 0
for ch in s:
n += ord(ch)
print(n)
print('c.')
l = []
for ch in s:
l.append(ord(ch))
print(l)
m = map(ord, s)
print(m)
print(list(m))
print([ord(ch) for ch in s])
入出力結果(Terminal, IPython)
$ ./sample1.py a. 112 121 116 104 111 98 b. 662 c. [112, 121, 116, 104, 111, 98] <map object at 0x103b144e0> [112, 121, 116, 104, 111, 98] [112, 121, 116, 104, 111, 98] $
0 コメント:
コメントを投稿