Python之父Guido在最近一次采访的最后说了啥

Python之父Guido在最近一次采访的最后说了啥?

在前些天的一次采访中,被问到Python未来发展方向的时候原文在infoworld,咱们可爱的python老爹Guido是这样说的:

One thing I want to point out are the SciPy and NumPy movements. Those people are introducing Python as a replacement for MatLab. It's open source, it's better, they can change it. They are taking it to places where I had never expected Python would travel. They have things like the Jupyter Notebooks that show interactive Python in the browser. There is a lot of incredibly cool work that is happening in that area.

简单翻译成中文就是说:在这里我要重点提一下SciPy 和 NumPy,做这些库的朋友们正在用Python替换MatLab,把Python带向了一个我从未想过的领域。他们发明了Jupyter Notebooks 可以在浏览器上进行Python的交互式编程。

注意到没? Jupyter Notebooks !

jupyter简介

jupyter是啥啊?
这个要从ipython说起,ipython是个交互式的python的解释器,自带颜色,补全还有行号,科学界的很多大牛都用来进行数据分析和图形显示。

ipython还可以运行在浏览器上,就是下面这个样子:

名字也就高大上一点,叫ipythoon notebook,那个jupyter图标一开始就有的,现在升级改造了,不止于运行python,还有R,spark之类的高大上玩意儿。所以就直接用 jupyter来指代这一堆产品了。

官方有个try页面,可以玩一玩。

https://try.jupyter.org/

jupyter安装

官方推荐的安装是这个:

Download Anaconda. We recommend downloading Anaconda’s latest Python 3 version (currently Python 3.5).

咱们民间可以直接安装
1.如果已经有python环境:

直接pip install jupyter

2.如果没有:
就先安装个python环境,然后再装

运行

jupyter notebook

然后就自动打开浏览器中localhost的8888端口,就可以在线写代码啦!不止于python,还有R等...

用户界面和主要功能

  • 写代码
  • 写文档(cell类型就分成markdown和code,随便改,另存为md格式就是文档了)
  • 科学运算和画图(numpy, scipy,pandas之类的以前都需要一个个安装啊,现在全齐了)

示例代码

简单计算器

4+6
10

写个字典

a = {'a':'alex', 'b':'sublime', 5:9999, 6:6666}
for k, v in a.items(): # items()是dict的方法,可以通过help(dict.items)查看
    print k,v
a alex
b sublime
5 9999
6 6666

这货是个装饰器

def show_output(func):
    def wrapped(*args, **kwargs):
        output = func(*args, **kwargs)
        print("the result is : ", output)
    return wrapped

def is_even(num):
    return num % 2 ==0

使用装饰器运行函数,并输出结果

f = show_output(is_even)
f(3)

the result is :  False

Jupyter对Python初学者的作用

对于初学者,难免编程过程中会出现各种错误,jupyter就是个代码摄像机,写代码时候出错了,看到一堆错误提示,没关系,从新插入一个cell,再次写起来!直到正确为止!

下面举个例子!

第一个错误

# 假装我不会写helloworld
print hello world

  File "<ipython-input-1-e9edef3fb57e>", line 2
    print hello world
                    ^
SyntaxError: invalid syntax

第二个错误

# 难道加个引号?
print 'hello world"
  File "<ipython-input-2-efbc3c88a80d>", line 2
    print 'hello world"
                      ^
SyntaxError: EOL while scanning string literal

啥情况?引号也不行?!

好吧,原来要写一对啊!

终于

# 这次对了吧?你好!世界!
print 'hello world'
hello world

ok,写到这里,错误代码有了,错误信息有了,最终也有了正确代码,再次回顾缩写代码的时候,可以清晰的看到自己犯过的错误,加深印象,有利于更快的掌握Python的语法和常见库函数的作用。

当然,在学会了Python基础之后,你可以选择继续用Jupyter中的各种数学库继续深造,使用numpy, scipy等进行数据分析与可视化。这方面已经有很多参考可以学习。

如果想做自动化开发和web开发,那么推荐你用另一个神器:pycharm,这里就不过多介绍了。

人身苦短,我用Python,学习Python的路上,你并不孤独!
完事开头难,学习Python最重要的是:实践,实线,再实践!如果你已经打开你的Jupyter notebook开始练习了,恭喜你!坚持下去,大法可成!

参考资源

原文地址:https://www.cnblogs.com/de8ug/p/python-jupyter-Guido.html