Category Python

Python Namespaces and Scope

Hierarchy of namespaces in Python

When we write a program in Python language, it is important to understand the concept of namespaces and scope. Both terms are closely related and are used to access variables, functions, and other objects in the program. A namespace in…

Modules in Python

In this tutorial, we will learn modules in Python, which we can invoke into any program to perform different tasks. So, let’s first understand what is a module. A module in Python is a file which contains a collection of…

Dictionary Comprehension in Python

Dictionary comprehension is the third type of comprehension in Python. It is a short-hand and powerful technique of creating a new dictionary from an existing dictionary or other iterable objects, such as list or tuple. Dictionary comprehension was introduced in…

Set Comprehension in Python

In addition to well-known list comprehension, Python also supports set comprehension. It is a short-hand way of creating a set from an existing iterable, such as a list or a tuple. It was introduced in the Python 3.0 version. Set…

List Comprehension in Python

Syntax of list comprehension in Python

List comprehension in Python is a short-hand way of creating a new list from an existing list or other iterable objects like a string, tuple, and dictionary. It was introduced in the Python 2.0 version. List comprehension is a powerful…