To get IP address of your computer in python, you have to first import socket library and then use socket.gethostbyname(socket.gethostname()) code inside the print() statement to print your IP address as output as shown in the program given below.
Following python program prints IP address of your computer:
# Python Program - Get IP Address import socket; print("Want to get IP Address ? (y/n): "); check = input(); if check == 'n': exit(); else: print("\nYour IP Address is: ",end=""); print(socket.gethostbyname(socket.gethostname()));
Here is the sample run of the above python program to illustrate how to get and print IP address of your computer:
Now supply y as input and press enter key to see the IP address of your computer system:
You may also like to learn or practice the same program in other popular programming languages: