$> python
Python 2.7.15 (default, Oct 2 2018, 11:47:18)
[GCC 4.2.1 Compatible Apple LLVM 10.0.0 (clang-1000.11.45.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> site = "www.flydean.com"
>>> site
'www.flydean.com'
>>>
python解释器的提示符是>>>。
python提供了一个非常有用的命令help,我们可以使用help来查看要使用的命令。
>>> help
Type help() for interactive help, or help(object) for help about object.
$> ipython
Python 3.6.4 |Anaconda, Inc.| (default, Jan 16 2018, 12:04:33)
Type 'copyright', 'credits' or 'license' for more information
IPython 6.2.1 -- An enhanced Interactive Python. Type '?' for help.
In [1]: site= "www.flydean.com"
In [2]: site
Out[2]: 'www.flydean.com'
IPython的提示符是In [1]:
基本上Python自带的命令在IPython中都是可以使用的。
IPython提供了4个非常有用的命令:
command
description
?
Introduction and overview of IPython’s features.
%quickref
Quick reference.
help
Python’s own help system.
object?
Details about ‘object’, use ‘object??’ for extra details.
魔法函数
IPython中有两种魔法函数,一种是Line magics,一种是Cell magics。
Line magics 接收本行的输入作为函数的输入,是以%开头的。而Cell magics可以接收多行的数据,直到你输入空白回车为止。是以%%开头的。
比如我们想要看一个timeit的魔法函数的用法,可以使用Object?来表示:
$> In [4]: %timeit?
Docstring:
Time execution of a Python statement or expression
Usage, in line mode:
%timeit [-n<N> -r<R> [-t|-c] -q -p<P> -o] statement
or in cell mode:
%%timeit [-n<N> -r<R> [-t|-c] -q -p<P> -o] setup_code
code
code...
In [11]: debug
> /Users/flydean/.pyenv/versions/anaconda3-5.1.0/lib/python3.6/site-packages/IPython/core/compilerop.py(99)ast_parse()
97 Arguments are exactly the same as ast.parse (in the standard library),
98 and are passed to the built-in compile function."""
---> 99 return compile(source, filename, symbol, self.flags | PyCF_ONLY_AST, 1)
100
101 def reset_compiler_flags(self):
ipdb>
In [12]: pdb
Automatic pdb calling has been turned ON
In [13]: pdb
Automatic pdb calling has been turned OFF