Yaswanth Varma

Yaswanth Varma

307 Articles Published

Articles by Yaswanth Varma

Page 25 of 31

Concatenated string with uncommon characters in Python?

Yaswanth Varma
Yaswanth Varma
Updated on 20-Jun-2025 1K+ Views

In Python, Strings are one of the commonly used data types that are used to store sequences of characters. In this article, we are going to learn to concatenate strings with uncommon characters in Python. The uncommon characters are the characters that appear in one string but not in the other string. For example, if str1="ABC" and str2="BCD", the uncommon characters are 'A' and 'D', and the concatenated result is "AD". Using set.symmetric_difference() Method The python set.symmetric_difference() method is used to return the new set that contains the elements that are in either of the sets, but ...

Read More

Python program to iterate over multiple lists simultaneously?

Yaswanth Varma
Yaswanth Varma
Updated on 20-Jun-2025 422 Views

In this article, we are going to learn how to iterate over multiple lists simultaneously. It is useful when the lists contain related data. For example, one list stores names, another stores genders, and the last one stores ages. By iterating over these lists simultaneously, we can access the necessary details of a single person. Iterating Over Multiple Lists using zip() Function The Python zip() function is a built-in function used to combine the elements from two or more iterator objects (such as lists, tuples, etc) and returns the result. The resultant iterator object contains tuples where the ith tuple ...

Read More

Python program to reverse bits of a positive integer number?

Yaswanth Varma
Yaswanth Varma
Updated on 19-Jun-2025 2K+ Views

In Python, every number is represented internally as a sequence of binary digits, known as bits. In this article, we are going to learn how to reverse the bits of a positive integer number. Reversing the bits of a Positive Integer Number If we reverse bits of an integer value, we are flipping the order of its binary digits such that the least important bit becomes the most important and vice versa.  The Python bin() Function: The Python bin() function accepts an integer value and converts the given integer to its binary representation. Following is the syntax of this ...

Read More

Python program to print a checkboard pattern of n*n using numpy.

Yaswanth Varma
Yaswanth Varma
Updated on 17-Jun-2025 714 Views

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

How to retrieve Python module path?

Yaswanth Varma
Yaswanth Varma
Updated on 17-Jun-2025 1K+ Views

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

What is the difference between dir(), globals() and locals() functions in Python?

Yaswanth Varma
Yaswanth Varma
Updated on 17-Jun-2025 905 Views

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

Why is indentation important in Python?

Yaswanth Varma
Yaswanth Varma
Updated on 17-Jun-2025 1K+ Views

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

Python program to print all sublists of a list.

Yaswanth Varma
Yaswanth Varma
Updated on 17-Jun-2025 6K+ Views

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

Map function and Dictionary in Python to sum ASCII values

Yaswanth Varma
Yaswanth Varma
Updated on 17-Jun-2025 910 Views

In this article, we are going to learn how to use the map() function along with dictionaries to add the ASCII values of characters in the string. The Python built-in ord() function returns the ASCII integer value of a character. Additionally, dictionaries (dict) in Python are used to store key-value pairs. We use them to associate strings with their total ASCII values, making it easy to store and retrieve the result. Before diving into the examples, let's have a quick look at the Python map() function and the Python ord() function. Python map() Function The Python map() function ...

Read More

Python program to create 3D list.

Yaswanth Varma
Yaswanth Varma
Updated on 17-Jun-2025 2K+ Views

In Python, A 3D list is also called a three-dimensional array (list of lists of lists). It can be visualized as a cube or a set of tables stacked together. It is commonly used to represent data with three indices. For example, a matrix of images (height, width, depth). In this article, we are going to learn how to create a 3D list. As Python does not have built-in support for multi-dimensional arrays like other programming languages, but using the nested lists and loops, we can create and manipulate 3D lists. Creating a 3D List In the following example, ...

Read More
Showing 241–250 of 307 articles
« Prev 1 23 24 25 26 27 31 Next »
Advertisements