Articles on Trending Technologies

Technical articles with clear explanations and examples

Fraction module in Python

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 25-Mar-2026 7K+ Views

Python's fractions module provides support for rational number arithmetic. Using this module, we can create fractions from integers, floats, decimals, strings, and other numeric values. The Fraction constructor accepts a numerator and denominator as parameters. The default numerator is 0 and the default denominator is 1. It raises ZeroDivisionError when the denominator is 0. Creating Fraction Instances Let's see how to create fractions using numerator and denominator values ? from fractions import Fraction print(Fraction(45, 54)) print(Fraction(12, 47)) print(Fraction(0, 15)) print(Fraction(10)) # denominator defaults to 1 5/6 12/47 0 10 ...

Read More

How to get synonyms/antonyms from NLTK WordNet in Python

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

The WordNet is a part of Python's Natural Language Toolkit. It is a large word database of English Nouns, Adjectives, Adverbs and Verbs. These are grouped into some set of cognitive synonyms, which are called synsets. To use the Wordnet, at first we have to install the NLTK module, then download the WordNet package. $ sudo pip3 install nltk $ python3 >>> import nltk >>> nltk.download('wordnet') In the wordnet, there are some groups of words, whose meaning are same. Let's explore how to extract synonyms, antonyms, and word details using NLTK WordNet. Getting Word ...

Read More

Quickly convert Decimal to other bases in Python

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

To quickly convert decimal numbers to other bases, Python provides built-in functions that make the process simple and efficient − Decimal to Binary − bin() Decimal to Octal − oct() Decimal to Hexadecimal − hex() The decimal number system has base 10 and uses digits 0-9. Binary (base 2) uses only 0 and 1. Octal (base 8) uses digits 0-7. Hexadecimal (base 16) uses digits 0-9 and letters A-F (where A=10, B=11, C=12, D=13, E=14, F=15). Convert Decimal to Binary The bin() function converts a decimal number to its binary representation ? ...

Read More

Implementing Photomosaics in Python

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

A photomosaic is a technique where an image is divided into a grid of squares, with each square replaced by other images or colored blocks. When viewed from a distance, the original image is visible, but up close, you see individual colored tiles creating the mosaic effect. In Python, we can create photomosaics using the photomosaic module, which provides an easy way to generate stunning mosaic effects from any image. Installation Install the photomosaic module using pip ? pip install photomosaic This will also install the required scikit-learn dependency. Key Features ...

Read More

Generating Random id's using UUID in Python

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

UUID stands for Universal Unique Identifier, a Python library that generates 128-bit unique identifiers for random objects. These identifiers are guaranteed to be unique across different systems and time periods. Advantages of UUID Generates unique random IDs for objects without requiring a central authority Useful for cryptography and hashing applications Perfect for generating unique identifiers for documents, database records, and network addresses No collision risk when generating IDs across distributed systems Using uuid1() - Time-based UUID The uuid1() function generates a UUID based on the current timestamp and MAC address ? import ...

Read More

Addition and Blending of images using OpenCv in Python

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

OpenCV allows us to perform mathematical operations on images by treating them as matrices. When working with images, we deal with different matrix types: binary images (0, 1), grayscale images (0-255), or RGB images (0-255 for each channel). To add two images, we simply add their corresponding matrices element-wise. OpenCV provides the cv2.add() function for image addition and cv2.addWeighted() for blending. Both operations require images of the same dimensions. Addition of Two Images The cv2.add() function performs pixel-wise addition of two images. If the sum exceeds 255, it gets clipped to 255 (saturation arithmetic) ? ...

Read More

Dunder or magic methods in python

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

Dunder methods (also called magic methods) are special methods in Python that allow us to define how objects behave with built-in operations. These methods are identified by double underscores (__) as prefix and suffix, like __init__ or __str__. Basic Object Representation Without defining custom string representation, Python objects display their memory location ? class String: # magic method to initiate object def __init__(self, string): self.string = string # object creation my_string = String('Python') # print object location print(my_string) ...

Read More

Draw geometric shapes on images using Python OpenCv module

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

OpenCV provides powerful functions to draw geometric shapes on images. This capability is essential for image analysis, annotation, and visualization tasks where you need to highlight specific regions or add visual markers. Creating a Blank Canvas First, let's create a blank image using NumPy to serve as our canvas ? import numpy as np import cv2 # Create a blank black image (350x350 pixels, 3 channels for BGR) my_img = np.zeros((350, 350, 3), dtype="uint8") cv2.imshow('Window', my_img) cv2.waitKey(0) cv2.destroyAllWindows() Drawing Lines The cv2.line() function draws straight lines between two points. It accepts these ...

Read More

Fetching top news using news API in Python

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

The News API is a popular service for searching and fetching news articles from various websites. Using this API, you can retrieve top headlines from news sources like BBC, CNN, and others. To use the News API, you need to register for a free API key at newsapi.org. Setting Up News API First, install the required library and get your API key ? pip install requests Register at newsapi.org to get your free API key. Replace "your_api_key_here" with your actual key. Fetching Top Headlines Here's how to fetch top news headlines from ...

Read More

Minkowski distance in Python

Sumana Challa
Sumana Challa
Updated on 25-Mar-2026 2K+ Views

The Minkowski distance is a metric in a normed vector space that measures the distance between two or more vectors. This metric is widely used in machine learning algorithms for measuring similarity between data points. The formula for calculating Minkowski distance is: D = (Σ|ri - si|p)1/p i=1 n Where: ri and si: Corresponding elements of two vectors in n-dimensional space p: Order parameter that determines the distance type. ...

Read More
Showing 7171–7180 of 61,303 articles
« Prev 1 716 717 718 719 720 6131 Next »
Advertisements