Pythonポケットリファレンス chapter07

条件制御のif文、if-else文、if-elif-else文
反復制御のwhile文、breakやcontinueを使う、while-else文、for文、range関数、zip関数、enumerate関数、breakやcontinueを使う、for-else文
例外処理は、ひとまず読むだけ。


最初は誰でも時間がかかるのさー、っていいわけ。

Pythonポケットリファレンス chapter05~06

勉強した記録を残していきます。

Chapter05 数値

演算と等号など数値の取り扱い。

aに2を足して、ふたたびaに入れる。
>>> a = 1
>>> a
1
>>> a += 2
>>> a
3
=ってのは、
>>> a = b = c = d = e = f = 1
>>> a += 3
>>> a
4
>>> b -= -5
>>> b
6
>>> c *= 3
>>> c
3
>>> d /= 1
>>> d
1
>>> e **= 5
>>> e
1
>>> f %= 1
>>> f
0

最初の「a=b=c=d=e=f=1」ってのが成り立つのか?と思ってしまった。=は「イコール」ではなく「代入する」って方の意味が強い。

最大最小
>>> abs(-112)
112
>>> list = [1,3,5,7,9,11]
>>> max(list)
11
>>> min(list)
1

Chapter06 文字列

文字の扱い方。

>>> 'id:olits'
'id:olits'
>>> "id:olits"
'id:olits'
文字の取り出しとスライス

文字は0から数える。左からは0,1,2...右からは-1,-2,-3と数える

>>> name = 'olits'
>>> len(name)
5
>>> name[2]
'i'
>>> name[-3]
'i'

スライスの時は文字と文字の間を数える。

>>> mail = 'hoge@huga.jp'
>>> mail[5:9]
'huga'
>>> mail[-7:-3]
'huga'
文字列操作
>>> ATCQ = 'a tribe called quest'
>>> ATCQ.find('call')
8
>>> ATCQ.find('LA')
-1
>>> atcq = ATCQ.replace('a', 'the')
>>> atcq
'the tribe cthelled quest'
>>> print atcq.split(' ')
['the', 'tribe', 'cthelled', 'quest']
>>> ATCQ.isupper()
False
>>> ATCQ.islower()
True

join()がうまくいかなかったな。


と、まぁ、今日はここら辺で。序盤からけっこう時間かかる、そんなもんか。

はじめまして数学〈1〉自然数を追え、無限を掴まえろ! / 吉田武

はじめまして数学〈1〉自然数を追え、無限を掴まえろ! (幻冬舎文庫)

はじめまして数学〈1〉自然数を追え、無限を掴まえろ! (幻冬舎文庫)

とりあえず、数学を学び直そうと思ってて、手頃なところから手を付けた。読み始める前はけっこう時間がかかるんじゃないかな、と思っていたんだけど、案外あっさり読めた。それだけ良書ってことか。

(あとで続きを書く)

Pythonポケットリファレンス chapter01〜04

Python ポケットリファレンス (Pocket Reference)Pythonを勉強していきます。最初の方はサクサクっとやる。

Chapter01 インストールと環境設定

やっておいた。

Chapter02 Hello Python !

>>> print 'Hello Python !'
Hello Python !

インデントは慣習的にスペース4つ。

Chapter03 Pythonの特徴と強み

>>> import this           
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

おお!訳がついてる

Chapter04 Python入門

if分とfor分の組み合わせのところ

>>> a = 1
>>> if a == 1 :
...   a = a+1
...   print a
... 
2
>>> b = [4,3,2,1]
>>> b
[4, 3, 2, 1]
>>> for e in b:
...   if e == a:
...     print e
... 
2

forの次のeは何でもない変数だ。

MacPortsを使ってPythonをインストールした

Pythonを勉強するためにPython2.6をインストールすることにした。公式サイトからインストーラーで入れるのがよかったんだけど、いろいろやってみたかったからMacPortsからインストールした。

macportsを入れる

を参考しました。

1.インストーラーをダウンロードしてインストール。
2.PATHを通す

export PATH=/opt/local/bin:/opt/local/sbin/:$PATH
export MANPATH=/opt/local/man:$MANPATH

3.MacPortsのアップデート

sudo port -d selfupdate
sudo port -d sync

4.使い方

#更新
sudo port sync

#検索
port search XXX

#インストール
sudo port install XXX

#インストール済み確認
port installed

#インストール済み更新
sudo port upgrade installed

#アンインストール
sudo port uninstall XXX

以上。

python2.6を入れる

を参考しました。

1.MacPortsからPythonをインストール

sudo port install python26

2.Pythonのバージョン選択ツールをインストール

sudo port install python_select

3.Pythonのバージョンを選択

#選択できるバージョンを確認
python_select -l

#バージョンを選択
sudo python_select python26

#バージョンを確認
python -v

以上、簡単だった。

Python2.6をインストールするときに時間が結構かかる。python_selectを使うときにsudoを使わないと、いつまでたっても切り替わらない。

はじめました

勉強の記録やノートとしてはてなを使います。ひとまずは勉強を続けることを目的とします。

まずは手元にある以下のものからやっていきます。

はじめまして数学〈1〉自然数を追え、無限を掴まえろ! (幻冬舎文庫)

はじめまして数学〈1〉自然数を追え、無限を掴まえろ! (幻冬舎文庫)

Python ポケットリファレンス (Pocket Reference)

Python ポケットリファレンス (Pocket Reference)

マンガでわかる統計学

マンガでわかる統計学