python get output of command to variable

import subprocess as sp
output = sp.getoutput('whoami --version')
print (output)

Here is what the above code is Doing:
1. We are importing the subprocess module.
2. We are using the getoutput() method of the subprocess module to execute the whoami command.
3. We are storing the output of the command in a variable called output.
4. We are printing the output.