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) 1-a, b, c, d, e, f, g, h, i.を解いてみる。
7.6(Exercises) 1-a, b, c, d, e, f, g, h, i.
入出力結果(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]: 'hello'.upper() # 'HELLO'
Out[1]: 'HELLO'
In [2]: 'Happy Birthday'!'.lower() # 'happy birthday!'
File "<ipython-input-2-c9bc3c165c03>", line 1
'Happy Birthday'!'.lower() # 'happy birthday!'
^
SyntaxError: invalid syntax
In [3]: quit()
macbook-pro:ch7 kamimura$ 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]: 'hello'.upper() # 'HELLO'
Out[1]: 'HELLO'
In [2]: 'Happy Birthday!'.lower() # 'happy birthday!'
Out[2]: 'happy birthday!'
In [3]: 'WeeeEEEEeeeEEEEeee'.swapcase() # 'wEEEeeeeEEEeeee'
Out[3]: 'wEEEeeeeEEEeeeeEEE'
In [4]: 'ABC123'.isupper() # True
Out[4]: True
In [5]: 'aeiouAEIOU'.count('a') # 1
Out[5]: 1
In [6]: 'hello'.endswith('o') # True
Out[6]: True
In [7]: 'hello'.startswith('H') # False
Out[7]: False
In [8]: 'Hello {0}'.format('Python') # 'Hello Python'
Out[8]: 'Hello Python'
In [9]: 'Hello {0}! Hello {1}!'.format('Python', 'World') # Hello Python! Hello World!'
Out[9]: 'Hello Python! Hello World!'
In [10]: quit()
$
0 コメント:
コメントを投稿