import socket
print(socket.gethostname())
This code uses the socket module to print the hostname of the machine it is run on.
Explanation:
-
import socketimports thesocketmodule. -
socket.gethostname()returns a string representing the hostname of the current machine. -
print(socket.gethostname())prints the hostname on the console.