close

How to shutdown a computer using Python

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to shutdown a computer using Python in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to shutdown a computer using Python?

  1. How to shutdown a computer using Python?

    or: if you want immediate shutdown without sudo prompt for password, use the following for Ubuntu and similar distro's:

  2. shutdown a computer using Python

    or: if you want immediate shutdown without sudo prompt for password, use the following for Ubuntu and similar distro's:

Method 1

import os
os.system('shutdown -s')

This will work for you.

Method 2

For Linux:

import os
os.system('sudo shutdown now')

or: if you want immediate shutdown without sudo prompt for password, use the following for Ubuntu and similar distro’s:

os.system('systemctl poweroff') 

Conclusion

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read