What is the 'time' in jupyter notebook?

Question:

What’s the type of time in jupyter notebook? Variable or function?

Below is my tests using python code.

Test 1:
enter image description here

Test 2:
enter image description here

Test 3:
enter image description here

Test 4:
enter image description here

Test 5:
enter image description here

Asked By: Jerry Chou

||

Answers:

time (or more properly, %time), is an IPython magic – a command that is otherwise not available directly in Python. As I noted, they are typically prefixed with % or %%% is for line magics, %% is for cell magics. If the automagic option is on, line magics can also be executed without the % character.

The () is not part of the IPython magic syntax. When you wrote time(), you were timing the expression (), which evaluates to an empty tuple.

IPython magic return values, if any, can be assigned to variables, but only when invoked with the % prefix:

a = %time

However, %time does not have a typical return value, so in the above example, a will be None.

Answered By: MattDMo