It has nothing to do with Python or NumPy specifically; that's a feature of ipython to run external programs, in this case, the head utility from the standard suite of *NIX command line utilities. head -4 just reads the first four lines of the file provided and echoes them to the terminal.
Videos
It has nothing to do with Python or NumPy specifically; that's a feature of ipython to run external programs, in this case, the head utility from the standard suite of *NIX command line utilities. head -4 just reads the first four lines of the file provided and echoes them to the terminal.
Using "!" means that you want to call a system command. If you are on a Linux/Unix system (Google Colab uses such a system for instance) then you can call Linux/Unix commands directly using "!". Looks like you are using a Windows system and the command "head" does not exist as a command in Windows. Assuming that you are using a locally hosted Jupyter Notebook, then it is running on a Windows system.
The head command itself is a command-line utility for outputting the first part of files given to it via standard input. It writes results to standard output. By default head returns the first ten lines of each file that it is given.
Under Python 3.x, you can do this nicely:
>>> head, *tail = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
>>> head
1
>>> tail
[1, 2, 3, 5, 8, 13, 21, 34, 55]
A new feature in 3.x is to use the * operator in unpacking, to mean any extra values. It is described in PEP 3132 - Extended Iterable Unpacking. This also has the advantage of working on any iterable, not just sequences.
It's also really readable.
As described in the PEP, if you want to do the equivalent under 2.x (without potentially making a temporary list), you have to do this:
it = iter(iterable)
head, tail = next(it), list(it)
As noted in the comments, this also provides an opportunity to get a default value for head rather than throwing an exception. If you want this behaviour, next() takes an optional second argument with a default value, so next(it, None) would give you None if there was no head element.
Naturally, if you are working on a list, the easiest way without the 3.x syntax is:
head, tail = seq[0], seq[1:]
>>> mylist = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
>>> head, tail = mylist[0], mylist[1:]
>>> head
1
>>> tail
[1, 2, 3, 5, 8, 13, 21, 34, 55]