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 8(Storing Collections of Data Using Lists)、8.9(Exercises) 11.を解いてみる。
8.9(Exercises) 11.
コード(BBEdit)
sample11.py
#!/usr/bin/env python3 #-*- coding: utf-8 -*- units = [['km', 'miles', 'league'], ['kg', 'pound', 'stone']] print('a.') print(units[-2]) print('b.') print(units[-1]) print('c.') print(units[-2][-3]) print('d.') print(units[-1][-3]) print('e.') print(units[-2][-2:]) print('f.') print(units[-1][:-1])
入出力結果(Terminal, IPython)
$ ./sample11.py a. ['km', 'miles', 'league'] b. ['kg', 'pound', 'stone'] c. km d. kg e. ['miles', 'league'] f. ['kg', 'pound'] $
0 コメント:
コメントを投稿