ch03-IPython:一种交互式计算和开发环境

ch03-IPython:一种交互式计算和开发环境

本章的目的是让你对IPython所提供的功能有一个全面的了解

本章提要

  1. Tab键自动完成
  2. 魔术指令
  3. 中断代码
  4. 给代码段计时

Tab键自动完成

1)提供拼写辅助

an_apple = 27
an<Tab>

2)提供方法预览和快捷输入

b = [1,2,3]
b.<Tab>

3)同样适用于包

import numpy
numpy.<Tab>

4)查询和补全文件路径

C:/<Tab>

这里尖括号里面Tab的意思是,按下Tab键,就会有相应的提示

魔术指令

1)查询变量

b?
Type:        list
String form: [1, 2, 3]
Length:      3
Docstring:  
list() -> new empty list
list(iterable) -> new list initialized from iterable's items

2)查询函数

In[16]add_numbers?
Signature: add_numbers(a, b)
Docstring:
Add two numbers together
Returns
 -------
the_sum: type of arguments
File:      c:\<ipython-input-8-497d83fb33d0>
Type:      function

KeyboardInterrupt

Ctrl-C

给代码段计时

In[18] %time a = [x**2 for x in range(1000)]
Wall time: 3 ms

更加精确的计时(重复多次去平均)

In[19] %timeit a = [x**2 for x in range(1000)]
1000 loops, best of 3: 369 µs per loop

出于时间和能力的限制本章很多东西没有涉及到,所以没有去深入了解,以后有需要可以查阅


Never mind happiness, do your mission

扫描二维码关注公众号,回复: 1459170 查看本文章

猜你喜欢

转载自blog.csdn.net/yfren1123/article/details/79201021
今日推荐