IPython - System Commands



If the statement in the input cell starts with the exclamation symbol (!), it is treated as a system command for underlying operating system. For example, !ls (for linux) and !dir (for windows) displays the contents of current directory

Exclamation Symbol (!) Command

The output of system command can also be assigned to a Python variable as shown below −

Output of system command

The variable stores output without colors and splits at newline characters.

It is also possible to combine Python variables or expressions with system command calls. Variable in curly brackets {} can be embedded in command text. Observe the following example −

System Command Calls

Here is another example to understand that prefixing Python variable with $ also achieves the same result.

Prefixing Python Variable
Advertisements