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 7(Using Methods)、7.6(Exercises) 8-a, b, c.を解いてみる。
7.6(Exercises) 8-a, b, c.
コード(BBEdit)
sample8.py
#!/usr/bin/env python3 #-*- coding: utf-8 -*- fruit = 'pineapple' print('a.') print(fruit.count('p')) # 3 print(fruit.find('p', 3)) # 5 print(fruit.find('p', fruit.count('p'))) # 5 print('b') print(fruit.upper()) # PINEAPPLE print('PINEAPPLE'.swapcase()) # pineapple print(fruit.count('pineapple')) # 1 print(fruit.count(fruit.upper().swapcase())) # 1 print('b.') print(fruit.swapcase()) # PINEAPPLE print(fruit.lower()) # pineapple print(fruit.replace('PINEAPPLE', 'pineapple')) # pineapple print(fruit.replace(fruit.swapcase(), fruit.lower())) # pineapple
入出力結果(Terminal, IPython)
$ ./sample8.py a. 3 5 5 b PINEAPPLE pineapple 1 1 b. PINEAPPLE pineapple pineapple pineapple $
0 コメント:
コメントを投稿