I was trying to run below command but getting invalid syntax error
$python
python 3.7.4
linux
>>> !ls
File "<stdin>", line 1
!ls
^
SyntaxError: invalid syntax
>>exit()
I was trying to run below command but getting invalid syntax error
$python
python 3.7.4
linux
>>> !ls
File "<stdin>", line 1
!ls
^
SyntaxError: invalid syntax
>>exit()
This is the shell assignment feature of IPython, not a core part of Python itself. The fact that you don't see the In [1]: style of prompts (you have >>>) means that you're not running IPython.
If you want to run a shell command from "normal" Python, the usual approach is with something like:
import os
os.system("whatever")
Just keep in mind the shell assignment feature is a tad more powerful than that.
If you need that feature, and you have IPython correctly installed, just run ipython instead of python.
if you are running it in jupyter notebook, it should work.
Based on the code, it shows you are running it on command prompt or shell.
if you are running it in command or shell prompt the Exclamatory symbol didnt work.
Try this approach
import os
os.system('ls')