Skip to the content.

Execute Python Code In Command Shell

We can run Python Code in shell using python -c option.

Example

$ python3 -c "print('Hello World')"
Hello World

Source: Python Docs