1-IPython的使用

Ipyhon快捷键

  • 单击M:转为markdown模式
  • 双击D:删除当前cell
  • ctrl + enter 运行本单元,选中下个单元
  • alt + enter 运行本单元,在下面插入一单元
  • shift + enter 运行本单元,选中下个单元
  • B 下方插入
  • A 上方插入
  • Y : 单元转入代码状态
  • M :单元转入markdown状态
  • alt + X 关闭浏览器
  • Shift-Tab : 提示

markdown 中可以使用html语法 abc

帮助文档

help(函数)

函数?

函数? 自己写的函数显示源码

Ipyhon魔法指令

运行外部python文件

%run *.py  # 当前路径

%run '/home/dai/Desktop/test.py'  

当我们使用魔法命令执行了一个外部文件时,该文件的函数就能在当前会话中使用

运行计时

用下面命令计算statement的平均运行时间:   
> %timeit statement

timeit会多次运行statement,最后得到一个更为精准的预期运行时间


可以使用两个百分号来测试多行代码的平均运行时间:

`
%%timeit

statement1

statement2

statement3

`

记住:
- %time一般用于耗时长的代码段
- %timeit一般用于耗时短的代码段

快速查看当前会话的所有变量与函数名称:

%who

查看当前会话的所有变量与函数名称的详细信息:

%whos

返回一个字符串列表,里面元素是当前会话的所有变量与函数名称:

%who_ls

执行linux指令

Linux指令:

$ echo "hello world" # echo is like Python's print function hello world

$ pwd # pwd = print working directory /home/jake # this is the "path" that we're sitting in

$ ls # ls = list working directory contents notebooks projects

$ mkdir mm /home/jake/projects

$touch txt !touch /home/nanfengpo/Desktop/xx/hello.txt

在Linux指令之前加上 !,即可在ipython当中执行Linux指令。

注意会将标准输出以字符串形式返回

更多魔法指令

lsmagic

你可能感兴趣的:(1-IPython的使用)