Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Python Articles
Page 703 of 855
Intersection() function Python
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 MoreThe intersection of two arrays in Python (Lambda expression and filter function )
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 MoreInplace Operators in Python - ixor(), iand(), ipow()
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 MoreInitialize Matrix in Python
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 MoreYouTube Media/Audio Download using Python - pafy
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
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 MoreUsing Iterations in Python Effectively
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 MoreUsing List as Stack and Queues in Python
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 MoreCustom len() Function In Python
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 MoreWhy importing star is a bad idea in python
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