how to shutdown your computer using python

import os

os.system("shutdown /s /t 1")

Here is what the above code is Doing:
1. Importing the os module
2. Using the os.system() function to execute the shutdown command
3. The shutdown command is followed by the /s switch, which tells the computer to shut down
4. The /t switch is followed by a number in seconds. This number tells the computer how long to wait before shutting down.