2014年3月5日水曜日

開発環境

Learning Python (Mark Lutz (著)、Oreilly & Associates Inc)のPART III.(Statements and Syntax)、Test Your Knowledge(Part III Exercises)、1.(Coding basic loops)を解いてみる。

その他参考書籍

1.(Coding basic loops)

コード(BBEdit)

sample.py

#!/usr/bin/env python3.3
#-*- coding: utf-8 -*-

# a
s = 'python ぱいそん 🐍'
for ch in s:
    print('{0}: {1}'.format(ch, ord(ch)))

# b
result = 0
for ch in s:
    result += ord(ch)
print(result)

# c
result = []
for ch in s:
    result.append(ord(ch))
print(result)
print(map(ord, s))
print(list(map(ord, s)))
print([ord(ch) for ch in s])

入出力結果(Terminal)

$ ./sample.py 
p: 112
y: 121
t: 116
h: 104
o: 111
n: 110
 : 32
ぱ: 12401
い: 12356
そ: 12381
ん: 12435
 : 32
🐍: 128013
178324
[112, 121, 116, 104, 111, 110, 32, 12401, 12356, 12381, 12435, 32, 128013]
<map object at 0x106dd0d50>
[112, 121, 116, 104, 111, 110, 32, 12401, 12356, 12381, 12435, 32, 128013]
[112, 121, 116, 104, 111, 110, 32, 12401, 12356, 12381, 12435, 32, 128013]
$

0 コメント:

コメントを投稿