Articles on Trending Technologies

Technical articles with clear explanations and examples

Print Colors of terminal in Python

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

In the terminal, if you want to make text appear in colored mode, there are numerous ways in Python programming to achieve it. Python offers several modules and built-in methods to add colors to terminal output. Using the termcolor Module The termcolor module provides ANSI color formatting for terminal output. It's one of the most popular libraries for adding colors to text. Installation First, install the termcolor module using pip − pip install termcolor Basic Usage Here's how to use termcolor to print colored text − import sys from ...

Read More

Replacing strings with numbers in Python for Data Analysis

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

In data analysis, converting categorical strings to numerical values is essential for machine learning algorithms and statistical analysis. Python provides several methods to map string values to integers efficiently. Consider this sample dataset with stock recommendations ? Company Industry Recommendation HDFC Bank Finance Hold Apollo Healthcare Buy Hero Automobile Underperform Yes Bank Finance Hold M&M Automobile Underperform Fortis Healthcare Buy We need to convert the Recommendation column to numerical values: Buy=1, Hold=2, Underperform=3. Method 1: Using ...

Read More

Pattern matching in Python with Regex

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

Regular expressions (regex) are a powerful tool for pattern matching and string manipulation in Python. The re module provides comprehensive regex functionality for finding, matching, and replacing text patterns. What is Regular Expression? A regular expression is a sequence of characters that defines a search pattern. In Python, the re module handles string parsing and pattern matching. Regular expressions can answer questions like ? Is this string a valid URL? Which users in /etc/passwd are in a given group? What is the date and ...

Read More

Why is python best suited for Competitive Coding

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

Competitive programming involves solving algorithmic problems efficiently using appropriate data structures within time constraints. Programmers must not only solve problems correctly but also optimize for time and space complexity. Here's an example of a typical competitive programming problem ? Given a string s of length n with only lowercase letters, calculate the number of ways to remove exactly one substring so that all remaining characters are equal. You must remove at least one character. While any programming language can solve such problems, Python offers unique advantages for competitive coding. Development Speed Python significantly ...

Read More

Performing Google Search using Python code?

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

In this article, we will learn how to perform Google searches using Python code. This is particularly useful when working on projects that need to access web data or integrate search results into your application. Prerequisites Python installed on your system Install the google module using pip ? pip install google Method 1: Getting Search Result URLs This approach returns a list of URLs from Google search results that you can use programmatically ? # Performing Google search and getting URLs class GoogleSearch: def __init__(self, ...

Read More

How to generate byte code file in python

Samual Sam
Samual Sam
Updated on 25-Mar-2026 2K+ Views

Python automatically compiles your source code to bytecode (stored in .pyc files) before executing it. This compiled bytecode is stored for faster execution on subsequent runs. When you import a module for the first time, or when your source file is newer than the existing compiled file, Python creates a .pyc file. In Python 3, these files are stored in a __pycache__ subdirectory rather than alongside your .py file. Automatic Bytecode Generation The simplest way to generate a .pyc file is to import the module ? # Create a simple module first (save as test_module.py) ...

Read More

Python program to check if a number is Prime or not

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 218K+ Views

A prime number is a natural number greater than 1 that has exactly two factors: 1 and itself. Numbers like 2, 3, 5, 7, 11 are prime numbers because they cannot be divided evenly by any other number except 1 and themselves. Let's say the following is our input − 7 The output should be as follows − Prime Number Using Basic Loop Method Let us check if a number is prime using a for loop by testing divisibility from 2 to half of the number − Example ...

Read More

Defining Clean Up Actions in Python

Samual Sam
Samual Sam
Updated on 25-Mar-2026 1K+ Views

There are numerous situations where we want our program to perform specific cleanup tasks, regardless of whether it runs successfully or encounters an error. While we commonly use try and except blocks to handle exceptions, Python provides a special clause for defining cleanup actions. The finally clause in a try statement is designed for defining cleanup actions that must be executed under any circumstances ? Basic Syntax try: raise SyntaxError("Sample error") finally: print("Learning Python!") Learning Python! Traceback (most recent call last): File "", ...

Read More

Writing files in background in Python

Samual Sam
Samual Sam
Updated on 25-Mar-2026 302 Views

Writing files in the background while performing other tasks simultaneously is achieved through multithreading in Python. This allows your program to continue executing other operations without waiting for file I/O operations to complete. Understanding Background File Writing When writing files in the background, we create a separate thread that handles the file operations independently from the main program flow. This is particularly useful for applications that need to log data or save information without blocking user interactions. Implementation Using Threading Here's how to implement background file writing using Python's threading module − import threading ...

Read More

Python program to print duplicates from a list of integers?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 3K+ Views

A duplicate element in a list is an item that appears more than once. Python provides several efficient methods to identify and extract duplicate elements from a list of integers. Let's say we have the following input list − [5, 10, 15, 10, 20, 25, 30, 20, 40] The output should display duplicate elements − [10, 20] Using For Loop with Dictionary This approach uses a dictionary to count occurrences and a nested condition to track duplicates − # Create a List numbers = [5, 10, 15, 18, ...

Read More
Showing 7131–7140 of 61,303 articles
« Prev 1 712 713 714 715 716 6131 Next »
Advertisements