*下位ページ [#ydce84f6] -[[Seaborn]] *参考 [#n66c183a] -入門 --http://www.pythonweb.jp/tutorial/ --http://www.tohoho-web.com/python/index.html *文法 [#f8f3bc94] -☆ --セミコロンなし,インデントが文法. --配列はmatlab式.[10, [20, 16], [32, u"太郎"], 18]など.スライス使える(a[1:2], a[:3], a[2:])が、スライス自体がリストにはならない.長さはlen(list),追記はlist.append(hoge). --数値配列の作成はrange(1, 5)など([1, 2, 3, 4]) --ifに括弧なし.if, elif, elseはすべて行末に: --forはmatlab式+行末に:.forのinに文字列は一文字ずつ取得.for, whileのあとにelseを入れることができる --コメントは#comment, """comment""" --数字->文字はstr(num).文字→整数はint(str),文字→浮動はfloat(str),数値判定はstr.isdigit() --論理演算子はor, and, not.真偽はTrue, False --関数はdef function_name(arg1, ...):.行末に:が必要 ---*でargs, **でパラメータを渡せる([[参照>http://www.tohoho-web.com/python/function.html#function]]) --intも含め配列の関数渡しも、「すべて」参照渡し -☆☆ --空オブジェクトはNone --空白文字削除はstr.strip() --[[Pythonは日本語がクソ>http://lab.hde.co.jp/2008/08/pythonunicodeencodeerror.html]] ---プログラムの入出力直後に,即効ですべてunicode型に変えてしまい,最後の出力でutf_8に変換して出力 ---utfへの変え方は,print (u"-" + unicode_string).encode('utf_8') *バブルソート [#t4875c64] def bubblesort(a): for i in range(len(a)-2): for j in range(len(a)-1-i): if a[j] < a[j+1]: tmp = a[j] a[j] = a[j+1] a[j+1] = tmp a=[2,4,5,1,2] bubblesort(a) for i in range(len(a)): print a[i] *ファイル [#y240e194] for line in open("test.txt", "r") line.strip() print line *正規表現 [#qa327b62] import re a = re.search(r'^[a-z]', line) |