This is known as a line magic in IPython. They are unique in that their arguments only extend to the end of the current line, and magics themselves are really structured for command line development. timeit
is used to time the execution of code.
If you wanted to see all of the magics you can use, you could simply type:
%lsmagic
to get a list of both line magics and cell magics.
Some further magic information from documentation here:
IPython has a system of commands we call magics that provide effectively a mini command language that is orthogonal to the syntax of Python and is extensible by the user with new commands. Magics are meant to be typed interactively, so they use command-line conventions, such as using whitespace for separating arguments, dashes for options and other conventions typical of a command-line environment.
Depending on whether you are in line or cell mode, there are two different ways to use %timeit
. Your question illustrates the first way:
In [1]: %timeit range(100)
vs.
In [1]: %%timeit
: x = range(100)
: