In [134]:
a = 5

In [135]:
a


Out[135]:
5

In [136]:
import numpy as np
data = {i : randn() for i in range(7)}

In [137]:
data


Out[137]:
{0: 0.8744839835329479,
 1: 0.15803953578108335,
 2: 0.47865954509893,
 3: 0.25184907332409234,
 4: 1.5313454123337007,
 5: 0.26798695346322915,
 6: -0.5274423804657942}

In [138]:
an_apple = 27
an_example = 42

In [139]:
b = [1,2,3]

In [140]:
b.pop()


Out[140]:
3

In [141]:
b


Out[141]:
[1, 2]

In [142]:
print b.count


<built-in method count of list object at 0x05427940>

In [143]:
import datetime

In [144]:
datetime.__class__


Out[144]:
module

In [145]:
i=5

In [146]:
j=str(i)

In [147]:
j


Out[147]:
'5'

In [148]:
print 5,'a'


5 a

In [149]:
print str(5) +  'a'


5a

In [150]:
path = 'book_scripts/ch02/names/yob1880.txt'

In [151]:
f = open(path)

In [152]:
lines = f.readlines

In [153]:
#randn??

In [154]:
#np.*load*?

In [155]:
%run ipython_script_test.py

In [156]:
a=5
b=6
c=7.5
result=f(a,b,c)

In [157]:
result


Out[157]:
1.4666666666666666

In [158]:
%cpaste


ERROR: Magic function `cpaste` not found.

In [159]:
a = np.random.randn(100,100)

In [160]:
%timeit np.dot(a,a)


1000 loops, best of 3: 426 us per loop

In [161]:
#%reset?

In [162]:
#%quickref

In [163]:
img = plt.imread('book_scripts/ch03/stinkbug.png')

In [164]:
imshow(img)


Out[164]:
<matplotlib.image.AxesImage at 0x690af10>

In [165]:
plot(randn(1000).cumsum())


Out[165]:
[<matplotlib.lines.Line2D at 0x697f490>]

In [166]:
from pylab import *
mpl.rcParams['font.sans-serif'] = ['SimHei'] #指定默认字体

mpl.rcParams['axes.unicode_minus'] = False #解决保存图像是负号'-'显示为方块的问题

t = arange(-5*pi, 5*pi, 0.01)
y = sin(t)/t
plt.plot(t, y)
plt.title(u'这里写的是中文')
plt.xlabel(u'X坐标')
plt.ylabel(u'Y坐标')
plt.show()



In [167]:
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!

In [169]:
this??

In [170]:
s = """Gur Mra bs Clguba, ol Gvz Crgref

Ornhgvshy vf orggre guna htyl.
Rkcyvpvg vf orggre guna vzcyvpvg.
Fvzcyr vf orggre guna pbzcyrk.
Pbzcyrk vf orggre guna pbzcyvpngrq.
Syng vf orggre guna arfgrq.
Fcnefr vf orggre guna qrafr.
Ernqnovyvgl pbhagf.
Fcrpvny pnfrf nera'g fcrpvny rabhtu gb oernx gur ehyrf.
Nygubhtu cenpgvpnyvgl orngf chevgl.
Reebef fubhyq arire cnff fvyragyl.
Hayrff rkcyvpvgyl fvyraprq.
Va gur snpr bs nzovthvgl, ershfr gur grzcgngvba gb thrff.
Gurer fubhyq or bar-- naq cersrenoyl bayl bar --boivbhf jnl gb qb vg.
Nygubhtu gung jnl znl abg or boivbhf ng svefg hayrff lbh'er Qhgpu.
Abj vf orggre guna arire.
Nygubhtu arire vf bsgra orggre guna *evtug* abj.
Vs gur vzcyrzragngvba vf uneq gb rkcynva, vg'f n onq vqrn.
Vs gur vzcyrzragngvba vf rnfl gb rkcynva, vg znl or n tbbq vqrn.
Anzrfcnprf ner bar ubaxvat terng vqrn -- yrg'f qb zber bs gubfr!"""

d = {}
for c in (65, 97):
    for i in range(26):
        d[chr(i+c)] = chr((i+13) % 26 + c)

print "".join([d.get(c, c) for c in s])


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!

In [175]:
class Message:
    def __init__(self, msg):
        self.msg = msg
    def __repr__(self):
        return 'Message: %s' % self.msg

In [176]:
x = Message('I have a secret')

In [177]:
x


Out[177]:
Message: I have a secret

In [ ]: