35: Python Program to find the System Hostname

Question: Write a program in Python to find the System Hostname.

Solution:

import socket

device_hostname = socket.gethostname()

print(device_hostname)
Output:
Python-get-System-Hostname-Google-Colab
Python-get-System-Hostname-mac

Reference:

- https://docs.python.org/3/library/socket.html

Comments & Discussion

Facing issues? Have questions? Post them here! We're happy to help!