Python Articles

Page 703 of 855

Intersection() function Python

Pavitra
Pavitra
Updated on 25-Mar-2026 320 Views

In this article, we will learn about the intersection() function that can be performed on any given set. According to mathematics, intersection means finding common elements from two or more sets. Set A {1, 2, 3, 4} Set B {3, 4, 5, 6} 3, 4 Intersection Set Intersection Syntax .intersection(, , ...) ...

Read More

The intersection of two arrays in Python (Lambda expression and filter function )

Pavitra
Pavitra
Updated on 25-Mar-2026 778 Views

In this article, we will learn about finding the intersection of two arrays in Python using lambda expressions and the filter function. The intersection contains elements that are common to both arrays. The problem is that we are given two arrays and we need to find the common elements between them using functional programming concepts. Algorithm Here's the step-by-step approach ? Declare an intersection function with two array parameters Use a lambda expression with the filter function to select elements from the second array that exist in the first array Convert the filtered result to ...

Read More

Inplace Operators in Python - ixor(), iand(), ipow()

Pavitra
Pavitra
Updated on 25-Mar-2026 346 Views

In this article, we will learn about some of the inplace operators available in Python's operator module. Python provides methods to perform inplace operations, combining assignment and computation simultaneously using a single statement. Here we will discuss three important inplace operators: ixor(), iand(), and ipow() functions. ixor() - Inplace XOR Operation This function performs an inplace XOR (exclusive or) operation. It behaves like the a ^= b operation, computing the bitwise XOR of two values ? import operator as op # using ixor() to perform XOR operation result = op.ixor(786, 12) # displaying ...

Read More

Initialize Matrix in Python

Pavitra
Pavitra
Updated on 25-Mar-2026 4K+ Views

In this article, we will learn how to initialize a matrix using two dimensional lists in Python. A matrix is a rectangular array of numbers arranged in rows and columns, which can be represented as a list of lists in Python. Let's explore different methods to initialize matrices, taking advantage of Python's list comprehension feature for clean and efficient code. Method 1: Using List Comprehension List comprehension provides an intuitive way to initialize matrices. We create the inner lists first and then extend to multiple rows ? # Define matrix dimensions rows = 3 cols ...

Read More

YouTube Media/Audio Download using Python - pafy

Hafeezul Kareem
Hafeezul Kareem
Updated on 25-Mar-2026 1K+ Views

In this article, we will learn how to extract YouTube video details and download media using the pafy module in Python. The pafy library provides a simple interface to access YouTube video metadata and download content in various formats. Installation Install the pafy module using pip: pip install pafy The pafy module also requires youtube-dl as a backend dependency: pip install youtube-dl Verify the installation by importing the module: import pafy print("Pafy module imported successfully!") Pafy module imported successfully! Extracting YouTube Video Details ...

Read More

__name__ (A Special variable) in Python

Sarika Singh
Sarika Singh
Updated on 25-Mar-2026 3K+ Views

Python does not require a main function to start execution like many other programming languages. Instead, it uses a special built-in variable called __name__ to determine how a Python script is being executed (directly or imported as a module into another script). In this article, we will learn about the __name__ variable in Python and how to use it effectively. Understanding the __name__ Variable The __name__ variable is a built-in variable that holds the name of the current module. When you run a script directly, Python sets __name__ to __main__. If the same script is ...

Read More

Using Iterations in Python Effectively

karthikeya Boyini
karthikeya Boyini
Updated on 25-Mar-2026 293 Views

In this article, we will learn about different iteration methods in Python and their effective implementation. Python provides several approaches to iterate through data structures, each with its own advantages and use cases. Using While Loop with Index This method uses a while loop with manual index management ? languages = ("Python", "C", "C++", "Java") print("The topics available on TutorialsPoint are:") i = 0 while (i < len(languages)): print(languages[i]) i += 1 The topics available on TutorialsPoint are: Python C C++ Java This ...

Read More

Using List as Stack and Queues in Python

karthikeya Boyini
karthikeya Boyini
Updated on 25-Mar-2026 7K+ Views

In this article, we will learn how to implement Stack and Queue data structures using Python lists. Both are fundamental data structures with different ordering principles: stacks follow LIFO (Last In First Out) while queues follow FIFO (First In First Out). We'll cover the core operations for both structures − Insertion operation (Push for stacks, Enqueue for queues) Deletion operation (Pop for stacks, Dequeue for queues) Display / Traversing operation ...

Read More

Custom len() Function In Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 25-Mar-2026 859 Views

The len() function in Python returns the number of items in an object. You can create a custom version by iterating through any iterable and counting its elements. How len() Works Internally Python's built-in len() function calls the __len__() method of an object. For custom implementation, we iterate through elements and count them manually. Creating a Custom Length Function Basic Implementation Here's how to implement a custom length function using iteration − def custom_length(iterable): """Calculate length of any iterable by counting elements""" count = 0 ...

Read More

Why importing star is a bad idea in python

Hafeezul Kareem
Hafeezul Kareem
Updated on 25-Mar-2026 574 Views

Importing all methods from a module using from module import * (star import) is considered a bad practice in Python for several important reasons. Problems with Star Imports Star imports create the following issues ? Namespace pollution − All module functions are imported into the current namespace Name conflicts − Imported functions can override your local functions Unclear code origin − Difficult to identify which module a function belongs to IDE limitations − Code editors cannot provide proper autocompletion and error detection Creating the Sample Module First, let's create a simple module file ...

Read More
Showing 7021–7030 of 8,549 articles
« Prev 1 701 702 703 704 705 855 Next »
Advertisements