The cyclic rotation of an array involves moving every element of the array one position forward, and the last element gets moved to the first position. For example, if the given array is [1, 2, 3, 4] then the array after one cyclic rotation is [4, 1, 2, 3]. In this article, we are going to learn how to cyclically rotate an array by one position using Python. Using Python insert() and pop() Methods The Python insert() method is used to insert or add an element at the specified index. The index value starts from zero. Following ... Read More
The checkboard pattern is the square grid composed of alternating 0s and 1s, arranged in a way that no two adjacent cells have the same value. It looks like the chessboard, where black and white squares alternate in every row and column. This kind of pattern is not only seen in chess or checkers, but also in image processing, graphics, and visualization, etc. In this article, we are going to learn how to print a checkboard pattern of n*n using numpy. Using Python numpy.indices() Method The numpy.indices() method is used to return the grid of indices with ... Read More
In Python, every module exists in a specific file path within the file system. Sometimes, we need to find out where the module is located to perform different operations, like debugging or verifying the version of the module. In this article, we will explore how to retrieve the file path of a module. Retrieving Path of a Standard Library Module In this approach, we are going to import the built-in os module, which is part of the Python standard library, and use the 'os.__file__()' to get the absolute path to the actual ".py" or ".pyc" file where the ... Read More
The Python built-in functions, dir(), globals(), and locals are used to provide insights into the objects, variables, and identifiers present in various scopes. They might look similar, but each function serves a different purpose and behaves differently depending on where and how it is used. In this article, we will discuss the difference between the dir(), globals(), and locals() in Python. Python dir() Function The Python dir() function is used to list the names in the current local scope or the attributes of an object. If no argument is passed, it returns the list of names ... Read More
Indentation indicates the spaces or tabs placed at the beginning of a line of code to indicate the block structure. In many programming languages, indentation is used to improve code readability. In Python, indentation is the key part of the syntax. It is used to define the blocks of code, such as loops, conditionals, and functions. If indentation is not used properly in Python, it results in the IndentationError, causing the program to fail. Using without Indentation In this scenario, we are going to use the If-Else statement in the Python program without proper indentation and observe the output. ... Read More
Identifiers are the names used to identify variables, functions, classes, and other objects. A valid identifier helps Python users to assign readable and meaningful names to the elements within the code. To be considered a valid identifier in Python must follow a specific set of rules. Rules For Valid Python Identifiers Following is a list of rules that are to be followed to consider as a valid identifier - The name must begin with the letter (A-Z or a-z) or an underscore. Identifiers cannot be keywords (like if, ... Read More
Seaborn is a Python visualization library built on top of matplotlib. It provides the interface for drawing statistical graphics. It simplifies the process of creating complex visualizations such as histograms, bar plots, etc. In this article, we are going to learn how to plot a graph using Seaborn in Python. To use Seaborn, we need to install it by using the command below. pip install seaborn Now, import the required libraries: import seaborn as sns import matplotlib.pyplot as plt Using seaborn.lineplot() Method The seaborn.lineplot() method is used to draw a line plot with the possibility of ... Read More
Printing sublists in PythonThe sublist is a portion of the list that contains one or more elements from the original list. These sublists can be contiguous(elements appear in the same order) or non-contiguous(where elements are taken from different positions). Example: Printing all Contiguous SublistsLet's look at the following example, where we are going to print all the contiguous sublists of the given list using nested loops. def demo(a): for i in range(len(a)): for j in range(i, len(a)): print(a[i:j+1]) x ... Read More
The string manipulation is the common task in the python programming, especially when working with the text based data. In this article we will explore how to reverse each word in a sentence. Generally, we reverse the entire sentence, where the both characters and the word positions are flipped, but in this task we are reversing only characters within each word while maintaining the original sequence of the words. For example if the input is "Welcome", the expected output would be "emocleW". Using Python split() Method The Python split() method is used to split all the words in ... Read More
Reserved keywords are the special words that are predefined by the language. These keywords are used to define the structure and syntax of the Python programs. They cannot be used as variable names, function names, or identifiers. Python has a fixed set of keywords that are recognized by the interpreter, and these keywords cannot be redefined. The Python keywords are case sensitive. To view all the keywords in the current Python version, we can use the built-in keyword module along with the 'keyword.kwlist' attribute to return the list of all the reserved keywords in Python as a list ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP