Python Program to Get Country Information
Last Updated :
20 Feb, 2023
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
from countryinfo import CountryInfo
name = input ( "Enter your country : " )
country = CountryInfo(name)
print ( "Capital is : " ,country.capital())
print ( "Currencies is :" ,country.currencies())
print ( "Language is : " ,country. languages())
print ( "Borders are : " ,country.borders())
print ( "Provinces are : " , country.provinces())
print ( "Area are : " , country.area())
print ( "Calling are : " , country.calling_codes())
print ( "Capital Latitudes and Longitudes are : " ,
country.capital_latlng())
print ( "TimeZone : " , country.timezones())
print ( "Population : " , country.population())
print ( "Others names : " ,country.alt_spellings())
|
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
Share your thoughts in the comments
Please Login to comment...