Open In App

Python Program to Get Country Information

Last Updated : 20 Feb, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

This tutorial will show you how to use Python modules to obtain the country’s information. We will utilize the countryinfo module for this purpose, which will assist in obtaining information about the capital, currencies, official language, and numerous other types of things that are probably present in that nation.

What is countryinfo in Python?

The countryinfo is a Python module that helps to extract information about any country about the properties of that country, including ISO information, states, languages spoken, currencies, and various other details. The countryinfo module in Python is that it’s easy to use and it is an open-source module. Use the following command to install the Countryinfo module in the Terminal window:

pip install countryinfo

Code Implementation

Import the CountryInfo module. Use the input() function to enter the country’s name. Give the new function CountryInfo() the country name and store it in a variable. Give a string containing a country’s name to CountryInfo() to create an instance of that class. Use a number of API methods to manipulate the CountryInfo object you created. Use the dot function to access the necessary information and the country’s specifics. After obtaining the details, print each one individually.

Python3




# Import the required module
from countryinfo import CountryInfo
 
# Input the Name of the Country
name=input("Enter your country : ")
 
# Passing the country name to the in-built function of the module
country = CountryInfo(name)
 
# Printing all the details using the Pre-defined Functions
 
# 1) Printing the Capital of the Country
print("Capital is : ",country.capital())
 
# 2) Printing the Currency used in the Country
print("Currencies is :",country.currencies())
 
# 3) Printing the Languages spoken in the Country
print("Language is : ",country. languages())
 
# 4) Printing the Borders of the Country and Function
# returns bordering countries (ISO3) for a specified country
print("Borders are : ",country.borders())
 
# 5) Printing the Provinces of the Country
print("Provinces are : ", country.provinces())
 
# 6) Printing the Areas in the Country
print("Area are : ", country.area())
 
# 7) Printing the Country Code of the Country
print("Calling are : ", country.calling_codes())
 
# 8) Printing the Latitudes and Longitudes of the Country
print("Capital Latitudes and Longitudes are : ",
                          country.capital_latlng())
 
# 9) Printing the TimeZone in the Country
print("TimeZone : ", country.timezones())
 
# 10) Printing the Current Population in the Country
print("Population : ", country.population())
 
# 11) Printing the Other Names of the Country
print("Others names : ",country.alt_spellings())
 
# This Code is Contributed by PL VISHNUPPRIYAN


Output:

 

The output displays all the information about India namely, Capital, Currency, Language, borders, population, and more.

For India:

Output: India

For the United States of America

Output: United States of America

For Germany:

Output: Germany

For Australia:

Output: Australia



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads