×

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

Multiple Linear Regression using Python

Linear Regression: Linear regression is a method that models the relationship between a dependent variable and one or more independent variables; in other terms, that models the relationship between a target...

6 minutes read.

Python float()

Python float() class The float() class in Python returns a floating point number constructed from a number or string x. Syntax class float([x]) Parameter x: This parameter represents a number or a string that can be converted...

1 minute read.

Find Words in String Python

Python : Python programming language is considered a general purpose; it is a high-level programming language that is not much difficult but easier to learn. Python programming language is rich in...

5 minutes read.

List Comprehension in Python

Sometimes we need new lists that are completely based on previously existing lists, so to perform this operation successfully, some of the programming languages come with a syntactic construct known...

5 minutes read.

One Liner If-Else Statements in Python

Before learning one liner if else Python, let us first know what Python is. Python is a broadly helpful, object-oriented and dependable language having a large number of utilizations from...

4 minutes read.

How to change the names of Columns in Python

Introduction To play with huge amounts of data, in Python we require a tool. The tool which is available in Python is Pandas. Pandas is an open-source library. It is used...

3 minutes read.

Python Set isdisjoint() method

Python Set isdisjoint() method The set.isdisjoint() method in Python returns a boolean value True if two sets are disjoint sets ( i.e. none of the elements are present in both sets), otherwise it returns...

1 minute read.

Python String isalnum() method

Python String isalnum() method The string.isalnum () method in Python returns a boolean value true if all characters in the string are alphanumeric else for any other value it returns false. Syntax String.isalnum() Parameter NA Return This...

1 minute read.

Check if the directory exists in Python

To prevent any error, while loading or editing a file, we first have to check that the directory or the file exists or not. This is also done to prevent...

5 minutes read.

Python And Operator

Python's and operator takes two operands that can be either object, Boolean expressions, or both. And operator creates more complex expressions using those operands. Conditions are the common name for...

8 minutes read.

Add Element to Tuple in Python

Python: Popular high-level, all-purpose programming language Python. The new version of the Python programming language, Python 3, is used for all software applications, including web development. Python is the best programming...

4 minutes read.

Python coding platform

Python is a popular general-purpose programming language with many applications. High-level data structures, datatypes, dynamic binding, and many other features make it useful for both designing complex applications and "glue...

6 minutes read.

Closest Pair of Points in Python

We are given an array of n points in the plane, and our task is to find the pair of points in the array that are the closest to each...

3 minutes read.

Python e-book free download

Python is a booming language these days. It has many applications for making code easier; it is also an open-source language. There are many sources to learn python. In this...

3 minutes read.

How to develop a game in python

Fun always makes a task interesting and easy to execute. Learning in the same theoretical way at some point reaches the boring spot. In this article, using some Python knowledge,...

13 minutes read.

How to Concat two Dataframes in Python

Using Pandas dataframe, we can concat two dataframes or series in Python. So let's take a brief introduction to what is Pandas in Python. Pandas is a library typically used for...

7 minutes read.

Matrix List Comprehension in Python

Introduction One of Python's most beautiful features is list comprehension. Iterating over an iterable object to create lists is a clever and succinct method. Nested List or matrix list Comprehensions, which...

6 minutes read.

Python format() function

Python format() function The format() function in Python formats a specified value into the given format. A ‘TypeErrorexception’ is raised if the method search reaches the object and the format_spec is non-empty, or if either the format_spec or the...

1 minute read.

Python tuple() function

Python tuple() function The tuple() function in Python creates a tuple object. Syntax tuple([iterable]) Parameter Iterable: This parameter represents a sequence, collection or an iterator object. Return This function returns a tuple object. Example 1 # Python Program explaining #...

1 minute read.

Python Variable Scope with Local & Non-local Examples

This article will examine Python's global, local and non-local variables and show you how to use them to write code without problems. Let's quickly review what a variable in Python is...

8 minutes read.