array with all countries in python

You can create a list of all countries in Python using a pre-defined list or by using an external package like pycountry. Here are two ways to create a list of all countries in Python:

Method 1: Using a pre-defined list

main.py
# Create a list of all countries
countries = ['Afghanistan', 'Albania', 'Algeria', 'Andorra', ... , 'Zambia', 'Zimbabwe']
122 chars
3 lines

Note: This list isn't comprehensive and would need to be updated to include any newly added countries.

Method 2: Using the pycountry package

main.py
# Install the pycountry package
!pip install pycountry

# Import the package
import pycountry

# Get all countries
countries = list(pycountry.countries)
countries = [country.name for country in countries]
205 chars
10 lines

This will give you a comprehensive list of all the countries in the world.

gistlibby LogSnag