Skip to content

Commit

Permalink
#5 コードやリンクがPython3に対応していなかったため修正
Browse files Browse the repository at this point in the history
  • Loading branch information
Akira-Taniguchi committed May 7, 2016
1 parent 24ff017 commit 1c19457
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 36 deletions.
21 changes: 10 additions & 11 deletions source/1_intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Pythonのソースコードをビルドし、インストールします(:numr

ソースコードのビルドで ``configure`` を実行する際に、 ``--prefix`` オプションを付けるとインストール先のディレクトリを指定できます。

/opt/python2.7.9 ディレクトリ以下にインストールするには、次のように指定します
/opt/python3.5.1 ディレクトリ以下にインストールするには、次のように指定します

.. code-block:: python
:caption: prefixオプション付きconfigure
Expand Down Expand Up @@ -150,9 +150,8 @@ Pythonインタープリタ
.. code-block:: bash
:caption: Pythonインタープリタの起動
$ python
Python 2.7.9 (default, Dec 29 2014, 17:03:36)
[GCC 4.8.2] on linux2
C:\Users\user>python
Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015, 01:54:25) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
Expand All @@ -177,7 +176,7 @@ Pythonを電卓にする
>>> 6 * 9
54
>>> 8 / 2
4
4.0
>>> 5 % 2
1
>>> width = 60
Expand Down Expand Up @@ -215,11 +214,11 @@ Pythonを電卓にする

.. admonition:: コラム: シーケンス型

シーケンス型は順序を持つ型で、Python標準では7つの型があります
シーケンス型は順序を持つ型で、Python標準では3つの型があります

シーケンス型の詳細はPythonの公式ドキュメントを参照してください。

* シーケンス型 http://docs.python.jp/2/library/stdtypes.html#typesseq
* シーケンス型 http://docs.python.jp/3.5/library/stdtypes.html#typesseq

リスト
-----------------
Expand Down Expand Up @@ -287,11 +286,11 @@ Pythonには標準でいくつか関数が提供されています。これを
:caption: 組み込み関数range
>>> range(10)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
range(0, 10)
組み込み関数の一覧は、次のドキュメントを参照してください。

* 組み込み関数 http://docs.python.jp/2/library/functions.html
* 組み込み関数 http://docs.python.jp/3.5/library/functions.html

FizzBuzz
=====================
Expand Down Expand Up @@ -334,7 +333,7 @@ Python インタープリタの対話モードを終了し(【Ctrl】+【D
def fizzbuzz(num):
return num
print fizzbuzz(4)
print(fizzbuzz(4))
この ``fizzbuzz()`` 関数はなにも処理をせず引数をそのまま返します。これから処理を追加していくので安心してください。
Expand Down Expand Up @@ -371,7 +370,7 @@ for文
return num
for num in range(1, 101):
print fizzbuzz(num)
print(fizzbuzz(num))
.. _fizzbuzz-2:
Expand Down
20 changes: 9 additions & 11 deletions source/2_types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ Pythonのデータ型(基本編)

はじめに
========
本節では整数型(``int``)、浮動小数点型(``float``)、文字列型(``str``)とUnicode文字列型(``unicode``)を扱います。
本節では整数型(``int``)、浮動小数点型(``float``)、文字列型(``str``)を扱います。

データ型については、Pythonの公式ドキュメントも参考にしてください。

* 組み込み型 http://docs.python.jp/2.7/library/stdtypes.html
* 組み込み型 http://docs.python.jp/3.5/library/stdtypes.html

整数型(int)
======================
Expand All @@ -35,25 +35,23 @@ Pythonのデータ型(基本編)
>>> 6 * 9
54
>>> 8 / 2
4
4.0
>>> 5 % 2
1
>>> 5 ** 2
25
整数型と整数型の商も整数型になることに注意してください。

小数点以下は切り捨てられます(:numref:`divide-int`)。
小数点以下も出力されます(:numref:`divide-int`)。

.. _divide-int:

.. code-block:: python
:caption: 整数型同士の商
>>> 10 / 3
3
3.3333333333333335
>>> 10 / 4
2
2.5
浮動小数点型(float)
=========================
Expand Down Expand Up @@ -108,9 +106,9 @@ Pythonのデータ型(基本編)
.. code-block:: python
:caption: 文字列中のエスケープ
>>> print 'I\'m Hiroki'
>>> print('I\'m Hiroki')
I'm Hiroki
>>> print 'Hello\nworld'
>>> print('Hello\nworld')
Hello
world
Expand All @@ -121,7 +119,7 @@ Pythonのデータ型(基本編)
.. code-block:: python
:caption: シングルクォートを含む文字列
>>> print "I'm Hiroki"
>>> print("I'm Hiroki")
I'm Hiroki
三重クォート
Expand Down
20 changes: 10 additions & 10 deletions source/3_collections.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ for文
:caption: for文とリスト
>>> for animal in ['cat', 'dog', 'snake']:
... print animal
... print(animal)
...
cat
dog
Expand Down Expand Up @@ -119,7 +119,7 @@ for文
他にも役に立つ書き方があるので、Pythonのドキュメントを参考にしてください。
* リストの内包表記 http://docs.python.jp/2/tutorial/datastructures.html#id6
* リストの内包表記 http://docs.python.jp/3.5/tutorial/datastructures.html#id6
しかし、複雑になりすぎる場合はループ処理で書きましょう。
Expand Down Expand Up @@ -333,7 +333,7 @@ in
>>> user_info.get('user_name')
'hirokiky'
>>> bio = user_info.get('bio')
>>> print bio
>>> print(bio)
None
``None`` は、Pythonの組み込み定数の1つで、何も値がないことを表します。
Expand Down Expand Up @@ -369,7 +369,7 @@ in
>>> d = {'foo': 'spam', 'bar': 'ham'}
>>> d.items()
[('foo', 'spam'), ('bar', 'ham')]
dict_items([('foo', 'spam'), ('bar', 'ham')])
``.items()`` の結果を ``for`` 文に渡せば、辞書内のすべての値を使った繰り返し処理を書けます。
Expand All @@ -382,7 +382,7 @@ in
>>> d = {'foo': 'spam', 'bar': 'ham'}
>>> for key, value in d.items():
... print key, value
... print(key, value)
...
foo spam
bar ham
Expand All @@ -408,9 +408,9 @@ in
:caption: 集合の定義
>>> {'spam', 'ham'}
set(['ham', 'spam'])
{'spam', 'ham'}
>>> {'spam', 'spam', 'spam'}
set(['spam'])
{'spam'}
.add()メソッド
--------------
Expand All @@ -426,7 +426,7 @@ in
>>> unique_users = {'dog', 'cat'}
>>> unique_users.add('snake')
>>> unique_users
set(['dog', 'snake', 'cat'])
{'dog', 'cat', 'snake'}
集合の長さも ``len()`` 関数で取得できます(:numref:`len-with-set`)。
Expand Down Expand Up @@ -464,7 +464,7 @@ in
>>> allowed_permissions = {'edit', 'view'}
>>> requested_permissions = {'view', 'delete'}
>>> allowed_permissions & requested_permissions
set(['view'])
{'view'}
:numref:`product-of-sets` では、アプリケーションから許可された権限の一覧 ``allowed_permissions`` を使って、ユーザに要求された権限 ``requested_permissions`` のフィルタリングを行う状況を想定しています。
結果としてユーザに許可された権限は ``'view'`` のみとなりました。
Expand All @@ -481,7 +481,7 @@ in
>>> editor = {'edit', 'comment'}
>>> reviewer = {'comment', 'approve'}
>>> editor | reviewer
set(['comment', 'edit', 'approve'])
{'comment', 'approve', 'edit'}
:numref:`sum-of-sets` では、``editor````reviewer`` はロール(役割)を想定しています。
この2つのロールを持つユーザは、``'edit'````'comment'````'approve'`` の権限を持つことを算出しました。
Expand Down
7 changes: 3 additions & 4 deletions source/4_module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ Pythonインタープリタを起動して、 ``calc.py`` をインポートし
>>> import calc
>>> calc
<module 'calc' from 'calc.py'>
``calc`` というモジュールがインポートされました。

Expand Down Expand Up @@ -146,7 +145,7 @@ Python自体も標準でモジュールを提供しています。これら標
>>> import re
>>> m = re.search('(P(yth|l)|Z)o[pn]e?', 'Python')
>>> m
<_sre.SRE_Match object at 0x7f4061d53308>
<_sre.SRE_Match object; span=(0, 6), match='Python'>
正規表現にマッチした場合、 ``re.search()`` は結果を表すマッチオブジェクトを返します。
マッチオブジェクトから値を取り出すには、 ``.group()`` メソッドを呼び出します(:numref:`match-object`)。
Expand Down Expand Up @@ -196,9 +195,9 @@ Python自体も標準でモジュールを提供しています。これら標
その他便利なモジュールについては、一部を「 :ref:`standard-library` 」で扱います。

``re`` モジュールには、ここで説明していない有効な使い方があります。
Pythonの公式ドキュメントの「 `reモジュール <http://docs.python.jp/2.7/library/re.html>`_ 」を参考にしてください。
Pythonの公式ドキュメントの「 `reモジュール <http://docs.python.jp/3.5/library/re.html>`_ 」を参考にしてください。

また、他のPython標準ライブラリについては、「 `Python標準ライブラリ <http://docs.python.jp/2.7/library/index.html>`_ 」を参考にしてください。
また、他のPython標準ライブラリについては、「 `Python標準ライブラリ <http://docs.python.jp/3.5/library/index.html>`_ 」を参考にしてください。

まとめ
==========
Expand Down

0 comments on commit 1c19457

Please sign in to comment.