Jyotsna Masand
Jyotsna Masand

Reputation: 103

Why does %%timeit work fine in Jupyter Notebook but throws SyntaxError in Python Shell IDLE?

%%timeit
d = deque()
for i in range(40000):
    d.appendleft(i)

The above code prints out the time of execution in Jupyter Notebook as: 3.39 ms ± 168 µs per loop (mean ± std. dev. of 7 runs, 100 loops each) However, when I run this code in Python IDLE Shell, it indicates SyntaxError at % in %%timeit. How is that so?

Upvotes: 0

Views: 3495

Answers (2)

Daweo
Daweo

Reputation: 36360

%%time is so-called Jupyter's magic command.

Upvotes: 1

Chen Xing
Chen Xing

Reputation: 1695

Because %% is Jupyter's "cell magic": https://ipython.readthedocs.io/en/stable/interactive/magics.html#cell-magics

It's not native Python syntax.

Upvotes: 0

Related Questions