create account

Python学习神器推荐 - Python Tutor by aafeng

View this thread on: hive.blogpeakd.comecency.com
· @aafeng ·
$29.60
Python学习神器推荐 - Python Tutor
对于很多初学者来说,Python中的众多概念极易混淆。在教自己孩子学习Python编程的时候就遇到了这样的问题,苦于无法直观的解释一些概念。最近发现的Python Tutor这个网站然我不禁眼睛一亮。这个网站可以让初学者直观的理解Python代码执行的过程,逐步可视化程序的运行过程。其最大的亮点就是把程序的执行过程在内存中的表现通过图形的方式来展示,这样就非常便于理解。

首先看下面一段简单的代码:

    b = [1, 3, 5, 7, 9]
    b = a
    a[0] = 0
    print(b[0])

代码很简单,展示了Python中的浅拷贝。但是对于初学者来说,怎样才能更加直观的理解这个概念呢?我们来看看Python Tutor中的演示:

![image](https://user-images.githubusercontent.com/63479035/84756975-741ca180-afbb-11ea-970c-6cc05f07b30a.png)

![image](https://user-images.githubusercontent.com/63479035/84757016-84cd1780-afbb-11ea-8c2e-6f8d5a9dfb6c.png)

![image](https://user-images.githubusercontent.com/63479035/84757076-91517000-afbb-11ea-9b85-50a9ada0cfd2.png)

通过上面的演示,可以非常直观的理解,其实a和b指向的是内存中的同一个对象,更改a[0]自然会导致b[0]也会被改变。

Python Tutor中还提供了一些自定制的功能,包括可以自定义演示的箭头,形状等:

![image](https://user-images.githubusercontent.com/63479035/84757255-d4abde80-afbb-11ea-8116-935130f6dc35.png)

在Python Tutor中有两种模式:在线编辑模式(Edit)和动态演示模式(Live)。简而言之,编辑模式就是一次性把代码写完,然后再统一运行,然后分步骤查看代码在内存中的表示。而动态演示模式则是在你键入代码的同时,Python Tutor会实时可视化代码在内存中的状态。

举一个代码深拷贝的例子来演示Python Tutor的动态演示模式。

首先键入如下代码:

    from copy import deepcopy

    a = [1, 3, 5, 7, 9]

你会看到如下的演示:
![image](https://user-images.githubusercontent.com/63479035/84764371-84d21500-afc5-11ea-809b-1093523a7d7c.png)

接下来分别进行浅拷贝和深拷贝:

    b = a
    c = deepcopy(a)

可以看到非常清晰的示意图:

![image](https://user-images.githubusercontent.com/63479035/84764624-ee522380-afc5-11ea-9e25-6ef146c49305.png)

看到这样的可视化演示,还有什么不能理解的呢?其实,除了Python程序的可视化演示,Python Tutor还有一系列的功能:Java Tutor, C Tutor, C++ Tutor, JavaScript Tutor, Ruby Tutor等来支持不同语言的可视化演示。
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 131 others
properties (23)
authoraafeng
permlinkpython-python-tutor
categoryhive-105017
json_metadata{"tags":["cn","cn-reader","cn-curation","cn-programming","python"],"image":["https://user-images.githubusercontent.com/63479035/84756975-741ca180-afbb-11ea-970c-6cc05f07b30a.png","https://user-images.githubusercontent.com/63479035/84757016-84cd1780-afbb-11ea-8c2e-6f8d5a9dfb6c.png","https://user-images.githubusercontent.com/63479035/84757076-91517000-afbb-11ea-9b85-50a9ada0cfd2.png","https://user-images.githubusercontent.com/63479035/84757255-d4abde80-afbb-11ea-8116-935130f6dc35.png","https://user-images.githubusercontent.com/63479035/84764371-84d21500-afc5-11ea-809b-1093523a7d7c.png","https://user-images.githubusercontent.com/63479035/84764624-ee522380-afc5-11ea-9e25-6ef146c49305.png"],"app":"hiveblog/0.1","format":"markdown"}
created2020-06-17 15:32:27
last_update2020-06-17 15:32:27
depth0
children0
last_payout2020-06-24 15:32:27
cashout_time1969-12-31 23:59:59
total_payout_value15.227 HBD
curator_payout_value14.370 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,571
author_reputation554,723,599,569,926
root_title"Python学习神器推荐 - Python Tutor"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id98,021,062
net_rshares62,777,814,547,585
author_curate_reward""
vote details (195)