Programming Articles

Page 615 of 2547

Generating Random id's using UUID in Python

karthikeya Boyini
karthikeya Boyini
Updated on 25-Mar-2026 971 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 551 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 808 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 791 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

Python program to convert floating to binary

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

A floating-point number is a number that has a decimal point and can represent both large and very small values. Binary representation uses only 0's and 1's in the base-2 numeral system. Converting floating-point numbers to binary in Python requires representing them in the IEEE 754 format (a standard for numerical representation using 1 bit for sign, 8 bits for exponent, and 23 bits for significand in 32-bit format). For example, the floating number 9.87 has the IEEE 754 32-bit binary representation "01000001000111011110101110000101". In this article, we will discuss different ways to convert floating-point numbers to binary using ...

Read More

Get similar words suggestion using Enchant in Python

Sumana Challa
Sumana Challa
Updated on 25-Mar-2026 509 Views

There will be times when we misspell some words when we write something. To overcome this problem, we use the PyEnchant module in Python. This module is used to check the spelling of words and suggest corrections for misspelled words. It is also used in many popular spell checkers, including ispell, aspell, and MySpell. It is very flexible in handling multiple dictionaries and multiple languages. For example, if the input is 'prfomnc', then the output returned would be − 'prominence', 'performance', 'preform', 'provence', 'preferment', 'proforma'. Installing PyEnchant For Windows users, install the pre-built binary packages using ...

Read More

Python Implementation of automatic Tic Tac Toe game using random number

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

This automatic Tic Tac Toe game simulates two players making random moves without human input. The game uses NumPy for board representation and random module for move selection, displaying the board after each turn until someone wins or the game draws. Required Modules The game requires NumPy for matrix operations and random for automated move selection ― import numpy as np import random from time import sleep Complete Implementation Here's the complete automatic Tic Tac Toe game with proper error handling ― import numpy as np import random from time import ...

Read More

Text Analysis in Python3

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

Text analysis involves extracting meaningful information from text files. Python provides powerful built-in functions to analyze various aspects of text data, including word counts, character statistics, and linguistic patterns. Text Analysis Functions • Word Count • Characters • Average Length • Stop Words • Special Chars • Numeric Data Reading Text Files First, let's create a sample text file and establish the basic file reading pattern ? # Create a sample text file sample_text = """Python ...

Read More
Showing 6141–6150 of 25,466 articles
« Prev 1 613 614 615 616 617 2547 Next »
Advertisements