python を使う上で、ipythonで使うと良いところみたなのを調べてみた
print表示より綺麗に表示される
In [11]: print data
{0: 0.49613688816136836, 1: 0.7609762428923907, 2: 0.5700416376550185, 3: 0.175291194455094, 4: 0.41368352630708494, 5: 0.5873027452343913, 6: 0.09669836847661195}
In [12]: data
Out[12]:
{0: 0.49613688816136836,
1: 0.7609762428923907,
2: 0.5700416376550185,
3: 0.175291194455094,
4: 0.41368352630708494,
5: 0.5873027452343913,
6: 0.09669836847661195}
タブ補完でlinaxのように使える
In [13]: an_apple =27
In [14]: an
an_apple and any
イントロスペクション(?でそのデータの情報を見ることができる)
In [9]: b=[1,2,3]
In [10]: b?
Type: list
String form: [1, 2, 3]
Length: 3
Docstring:
list() -> new empty list
list(iterable) -> new list initialized from iterable's items
# ??をつけるとその関数のソースコードがみれる
In [14]: def add_numbers(a,b):
....: return a+b
....:
In [18]: add_numbers??
Type: function
String form: <function add_numbers at 0x1077a32a8>
File: /Users/ykitagaw/<ipython-input-14-a9946ee651b1>
Definition: add_numbers(a, b)
Source:
def add_numbers(a,b):
return a+b
%runコマンド
%run test.py
runの後にファイル名を渡す。値もそのまま使える
%paste、、、コピペでコードを貼る
# 事前にコピーしておいてから
In [19]: %paste
for num in [4, 3, 12]:
print "num = " + str(num)
## -- End pasted text --
num = 4
num = 3
num = 12
# 自分で貼り付けるやり方もある
In [21]: %cpaste
Pasting code; enter '--' alone on the line to stop or use Ctrl-D.
:for num in [4, 3, 12]:
: print "num = " + str(num)
:<EOF>
num = 4
num = 3
num = 12