Python Programming Examples Tutorial Index

Python File I/O Programs

This Python example code demonstrates a basic Python program for getting country data about countries, ISO info, and states/provinces. It uses the CountryInfo Python module, which has some predefined functions to retrieve the data via API.



Example:

Python program to get data about countries:

# Importing the required module.
from countryinfo import CountryInfo

# Getting a country name from the user.
count=input("Please enter your country name: ")
country = CountryInfo(count)

#print(country.info()) # It returns the object with all the info about the country.

# Different APIs to get the data as per the requirements.
print("Others names : ",country.alt_spellings())
print("Capital is : ",country.capital())
print("Currencies is :",country.currencies())
print("Lanuage is : ",country.languages())
print("Borders are : ",country.borders())

Program Output:

Please enter your country name: Singapore
Others names :  ['SG', 'Singapura', 'Republik Singapura', '新加坡共和国']
Capital is :  Singapore
Currencies is : ['SGD']
Lanuage is :  ['en', 'ms', 'ta', 'zh']
Borders are :  []

Program Output:

Please enter your country name: India
Others names :  ['IN', 'Bhārat', 'Republic of India', 'Bharat Ganrajya']
Capital is :  New Delhi
Currencies is : ['INR']
Lanuage is :  ['hi', 'en']
Borders are :  ['AFG', 'BGD', 'BTN', 'MMR', 'CHN', 'NPL', 'PAK', 'LKA']

Install countryinfo

The countryinfo Python library can be installed using pip (package manager for Python). The following command installs the package:

pip install countryinfo


Found This Page Useful? Share It!
Get the Latest Tutorials and Updates
Join us on Telegram