1.?
查看指定变量的基本信息:?<var>
<var>?
#参数说明:
var:指定变量
#实例:
In [1]: a=12123
In [2]: ?a
Type: int
String form: 12123
Docstring:
int([x]) -> integer
int(x, base=10) -> integer
Convert a number or string to an integer, or return 0 if no arguments
are given. If x is a number, return x.__int__(). For floating point
numbers, this truncates towards zero.
If x is not a number or if base is given, then x must be a string,
bytes, or bytearray instance representing an integer literal in the
given base. The literal can be preceded by '+' or '-' and be surrounded
by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.
Base 0 means to interpret the base from the string as an integer literal.
>>> int('0b100', base=0)
4
######################################################################################################################
查看函数的基本信息:?<func>
<func>?
#参数说明:
func:指定函数;为function object
#实例:
In [3]: def f():
...:print("AAA")
...:
In [4]: f?
Signature: f()
Docstring: <no docstring>
File: c:\users\euler\<ipython-input-3-b6d585d7ac6a>
Type: function
2.魔术命令
执行指定.py文件:%run "<file>"
#参数说明:
file:指定要执行的.py文件;为str(路径+文件名(包括后缀名.py))
######################################################################################################################
显示所有模式命令:%magic
######################################################################################################################
查看之前输入的命令:%hist
######################################################################################################################
要求/取消异常发生自动进入pdb调试器:%pdb
#实例:
In [10]: %pdb
Automatic pdb calling has been turned ON
In [11]: asda
Traceback (most recent call last):
File "<ipython-input-11-4bbaa6a86649>", line 1, in <module>
asda
NameError: name 'asda' is not defined
> <ipython-input-11-4bbaa6a86649>(1)<module>()
----> 1 asda
ipdb> exit()#退出pdb调试器
In [12]: %pdb
Automatic pdb calling has been turned OFF
######################################################################################################################
删除当前命令空间中的全部变量:%reset
######################################################################################################################
显示当前命名空间中的所有变量:%who
######################################################################################################################
查看代码的执行时间:%time <statement>
#只执行1次指定代码并返回执行时间
查看代码的评价执行时间:%timeit <statement>
#会多次执行指定代码以求出平均执行时间
#参数说明:
statement:指定一段代码
#实例:
In [14]: %time print("AAAAAAA")
AAAAAAA
Wall time: 0 ns