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 while True: print("Want to get IP Address ? (y/n): ") check = input() if check == 'n': break else: print("Your IP Address is: ",end="") print(socket.gethostbyname(socket.gethostname())) print()
Here is the sample run of the above python program to illustrate how to get and print IP address of your computer:
You may also like to learn or practice the same program in other popular programming languages: