Python os.system() method explanation with example

How to use python os.system() method with example:

Python os.system() method is a method defined in os module of python. Python os module has many methods defines used for different operating system related tasks.

os.system() is used to execute a command. The output of the command is passed to the interpreter standard output stream. It is implemented by calling the standard c function system() and it has the same limitations.

Example of os.system:

Let’s take a look at the below program:

import os

os.system('python3 --version')

Here, we are not using any print statement. But, if we run this on linux or mac, it will print the python version on console.

python os system command

The result of os.system is sent to the standard output stream, which is the console in linux or mac.

You might also like: