×

Python pycountry

What is Pycountry?

Python programming language:

Python is an interactive and more accessible language than any other programming language. The python programming language uses a variety of libraries to perform the operations in a faster way. The python language can also be used in web development; Django and Flask are the frameworks used to create web applications using Python. In Python, indentation is the main concept; if we do not follow proper indentation, then the program will not run properly, and we will get an error in the output. Python programming language contains methods or functions to reduce the size of the code, and the python programming language provides built-in functions and user-defined functions. We can import the functions in the python programming language through the libraries, which can be downloaded using the python package manager ( pip ). While working on the project and we want to develop the project using the python programming language. Python programming language is an object-oriented and high-level language it is easier to learn when compared to other programming languages.

The python programming language contains mainly six built-in datatypes; these six data types help solve the problem efficiently and faster. The python programming language consists of a built-in function and provides libraries and modules that can be imported to solve the problem more efficiently. Generally, there are many versions of python interpreters available. Still, from them, we need to download the version of Python more significantly than or equal to 3.4 so that the code runs faster and we can observe the output in the console.

Pycountry:

The ISO databases for the standards are made available by PyCountry:

Languages -639-3

3166-  countries

3166-3 Removed countries

3166-2- Country subdivisions

currencies-4217

scripts,- 15924

The data is made accessible through a Python API by the package, which also includes a copy from Debian'spkg-isocodes. Additionally, translation files for the individual strings are provided.

Data Update Guidelines

The data will not be accepted into pycountry with any modifications. The pkg-isocodes database from Debian is used as is in this pure wrapper around the ISO standard. Please speak with the ISO or Debian people rather than me if you want changes made to the global political landscape.

Countries (ISO 3166) in Pycountry:

Countries are accessed through a database object that is already configured upon import of pycountry and functions as an iterable:

importpycountry
len (pycountry.countries)
249
>>>list(pycountry.countries) [0]

Country (name=Afghanistan, numeric=004, official name=Islamic Republic of Afghanistan, alpha 2='AF', alpha 3='AFG')

By looking for specific nations using their various codes, the attributes listed in the standard can be obtained

Germany = pycountry.countries.get.(alpha 2='DE' )
>> Germany
Country (alpha 2='DE', alpha 3='DEU', name='Germany', numeric='276', official name='Federal Republic of Germany') 
>>> Germany.alpha_3
‘DEU’
>>>Germany.name
‘276’
>>> Germany.aplha_3
‘DE’
>>>Germany.official_name
‘Fedral Republic of Germany’

In order to find "real" countries for names that may actually be subdivisions, there is also a "fuzzy" search option. Additionally, normalisingunicode accents is fuzzier. There is also some prioritising so that nations with more matches are listed before those with less matches and matches on country names are preferred before subdivision names:

>>>pycountry.countries.search_fuzzy('England')
[Country(alpha_2='US', alpha_3=’USA', name='United States', numeric='342', official_name='United States of America')]
>>>pycountry.countries.search_fuzzy('Cote')
[Country(alpha_2='NG', alpha_3='NIG', name="Nigeria", numeric='345', official_name="Republic of Nigeria"),
Country(alpha_2='PK', alpha_3='PAK', name='PAKISTAN', numeric='287', official_name='PAKISTAN')]

Scripts (ISO 15924) in Pycountry:

These are the different literatures available in the different countries these scripts are also available as the same dataset as the countries.

>>>len(pycountry.scripts)
157
>>>list(pycountry.scripts)[0]
Script(alpha_4='Artla', name='Artla', numeric='456')


>>>Malu_script = pycountry.scripts.get(name= ‘Malu')
>>>Malu
Script(alpha_4='Mal', name='Malu', numeric='218')
>>> Malu.alpha4
'Mal'
>>> Malu.name
'Malu'
>>>latin.numeric
'218'

Country Subdivisions (ISO 3166-2) in Pycountry:

Because they offer a nested and typed structure, the country subdivisions are a little more complicated than the nations themselves.

All subdivisions are directly accessible:

>>>len(pycountry.subdivisions)
5356
>>>list(pycountry.subdivisions)[0]
Subdivision(code='IND-07', country_code='IND', name=INDIA', parent_code=None, type='ASIAN')

Currencies (ISO 4217) in Pycountry

These are the different currencies available in the different countries these currencies are also available as the same dataset as the countries

countries>>>len(pycountry.currencies
182
>>>list(pycountry.currencies)[0]
Currency(alpha_3='USD', name='Dollar', numeric='768')
>>>Indin_rupee=pycountry.currencies.get(alpha_3='RUP')
>>>Indian_rupee

Languages (ISO 639-3) in pycountry

These are the different languagesavailable in the different countries these languages are also available as the same dataset as the countries

>>>len(pycountry.languages)
7874	
>>>list(pycountry.languages)[0]
Language(alpha_3='Tel', name='Telugu', scope='I', type='L')


>>>Marathi=pycountry.languages.get(alpha_2='Mt')
>>>Marathi.alpha_2
'Mt'
>>>Marathi.alpha_3
'Mrt'
>>>Marathi.name
'Marathi'
>>>kanada=pycountry.languages.get(alpha_2='kn')
>>>kanada.name
'Kanada'

Related Topics

Python variance() function

Variance The variance is the average of the square deviations from the mean. The variance will measure the spread of the dataset from its mean or median value. The greater the...

4 minutes read.

Loan calculator using Tkinter in Python

Tkinter: Tkinter, part of all common Python distributions, is the de facto method for creating Graphical User Interfaces (GUIs) in Python. The only framework included in the Python standard library is...

4 minutes read.

Find key from value in dictionary python

Python: Python programming language is one of the most used programming languages, as it is used widely in software and data analysis, web development, etc. It is said to be a...

5 minutes read.

Data Drop in Python

Introduction You'll understand how to delete a group of rows from a Pandas dataframe in this article.You can read this article on How to Drop Columns in Pandas to find out...

6 minutes read.

Allocate a minimum number of pages in python

You have given a sorted array of size n which represents the number of pages in n different books and an integer value which denotes the number of students. We...

4 minutes read.

Python Dictionary clear() method

Python Dictionary clear() method The dictionary.clear() method in Python removes all the elements from a dictionary. Syntax dictionary.clear() Parameter NA Return None Example 1 # Python program explaining # the dictionary.clear() method # initialising the dictionary fruits =...

1 minute read.

How to Read html page in python

Html is a Hyper Text Markup language is a standard language used for creating webpages. HTML is the name of the language used to describe the construction of Web pages....

4 minutes read.

Python Sending Email

Python Sending Email Simple Mail Transfer Protocol (SMTP) is used to handle sending e-mail and routing e-mail between mail servers. When we send an email either form a web-application or from a local software...

3 minutes read.

Python String capitalize() method

Python String capitalize() method The string.capitalize() method in Python returns a copy of the string with only its first character capitalized. Syntax string.capitalize() Parameter NA Return This function returns a string where the first character is upper...

1 minute read.

Tuple in Python

Tuples Tuples are the same as the list but as we know that lists are mutable means we can change the data from it. In the tuple we cannot change the...

6 minutes read.

Find whether the given stringnumber is palindrome or not

Problem statement Sam is found of playing with strings. One day he thought of finding whether a string is a palindrome or not. He wanted to develop a computer process to...

2 minutes read.

Python pycountry

What is Pycountry? Python programming language: Python is an interactive and more accessible language than any other programming language. The python programming language uses a variety of libraries to perform the operations...

4 minutes read.

any() Keyword in python

“any” keyword in python This page contains all the information about any () Keyword in python, how it is used with lists, tuples, dictionaries, sets, and what its function is? Python...

3 minutes read.

Python program to check if two strings are anagram or not

Python program to check if two strings are anagram or not Problem: This is a python program that takes two strings and checks if given strings are anagram or not. Examples: Input: string1...

1 minute read.

Python String split() method

The string.split() method in Python splits a string into a list and returns a list of the words in the string. If the parameter maxsplit is given, at most maxsplit splits are done. If maxsplit is...

2 minutes read.

Python PPTX

Python-pptx is a python library that enables the user to create and update PowerPoint (.pptx) presentations. It is used to create modified PowerPoint presentations from the db content that can...

10 minutes read.

Python Compiler

What is Compiler? The compiler is mainly a program used to convert the source code into the machine or binary code. The source code is generally a computer program written using...

6 minutes read.

What is Ipython shell?

IPython is a command shell for computing in multiple programming languages. IPython was developed for python language by Fernando Perez in 2001 as a well-equipped python interpreter that offers shell...

3 minutes read.

How to Define a Function in Python?

What is a Function? In programming, a piece of code that executes a specific task or a group of related operations is known as a function. What does Python Functions Do? If you...

6 minutes read.

Nested for Loop in Python

"Loop" is one of the foundation concepts to learn programming in any language. Nested loops are significant steps in solving many types of problems, ranging from basic to complex scenarios....

9 minutes read.