Online visitors

People learning around the world

Online

—

Visitors exploring W3Schools

Online visitors by country Circles show approximate country locations. The country list provides the visitor counts.

Circles represent countries, not exact visitor locations.

Country

Online

Loading country activity…

    Python Program to Get Country Information

    Python Programming Examples


    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

    Notifications

    Updates are enabled for this browser.

    Receive new tutorials, articles and learning resources. You can turn updates off anytime.