Articles on Trending Technologies

Technical articles with clear explanations and examples

Optimization Tips for Python Code?

Nitya Raut
Nitya Raut
Updated on 25-Mar-2026 405 Views

Python may not be as fast as compiled languages, but proper optimization techniques can significantly improve performance. Many large companies successfully use Python for heavy workloads by applying smart optimization strategies. Use Built-in Functions Built-in functions are written in C and are much faster than custom Python code. Always prefer built-ins when available ? # Fast - using built-in sum() numbers = [1, 2, 3, 4, 5] total = sum(numbers) print(total) # Slower - manual loop total = 0 for num in numbers: total += num print(total) 15 ...

Read More

Python Input Methods for Competitive Programming?

Vrundesha Joshi
Vrundesha Joshi
Updated on 25-Mar-2026 2K+ Views

In competitive programming, efficient input/output methods can significantly improve your solution's performance. Python offers several approaches for reading input, each with different speed characteristics. Let's explore various I/O methods using a simple example: reading four numbers a, b, c, d and printing their product. Basic Input Methods Using List Comprehension This method uses list comprehension to convert input strings to integers − a, b, c, d = [int(x) for x in input().split()] print(a * b * c * d) Using map() Function The map() function provides a cleaner syntax for type ...

Read More

Timeit in Python with Examples?

Jennifer Nicholas
Jennifer Nicholas
Updated on 25-Mar-2026 513 Views

Python provides the timeit module for precise timing measurements of small code snippets. Unlike the basic time module, timeit accounts for background processes and provides more accurate performance measurements. What is Python timeit? The timeit module runs code approximately 1 million times (default value) and measures the minimum execution time. This approach eliminates timing variations caused by background processes and system overhead. Using timeit from Command Line You can use timeit directly from the command line interface. The module automatically decides the number of repetitions ? C:\Users\rajesh>python -m timeit "'-'.join(str(n) for n in range(200))" ...

Read More

File Objects in Python?

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

In Python, file handling is a native feature that doesn't require importing any external libraries. The open() function opens a file and returns a file object, which contains methods and attributes for retrieving information or manipulating the opened file. File Operations Overview File operations in Python follow a standard sequence ? Opening a file Performing read or write operations Closing the file Opening a File The built−in open() function creates a file object. It takes two main arguments: the filename and ...

Read More

Detection of a specific color(blue here) using OpenCV with Python?

Jennifer Nicholas
Jennifer Nicholas
Updated on 25-Mar-2026 2K+ Views

Image processing and color detection might seem complex at first, but OpenCV makes it straightforward. In this tutorial, we'll learn how to detect specific colors (blue in this case) using Python and OpenCV. Understanding Color Models Computers represent colors using color models that describe colors as tuples of numbers. The two most common models are RGB (Red, Green, Blue) and HSV (Hue, Saturation, Value). RGB Color Model RGB represents colors as three components, each ranging from 0 to 255. The tuple (0, 0, 0) represents black, while (255, 255, 255) represents white. For pure blue, the ...

Read More

Linear Regression using Python?

Jennifer Nicholas
Jennifer Nicholas
Updated on 25-Mar-2026 908 Views

Linear regression is one of the simplest standard tools in machine learning to indicate if there is a positive or negative relationship between two variables. It's also one of the few good tools for quick predictive analysis. In this tutorial, we'll use Python pandas package to load data and then estimate, interpret and visualize linear regression models. What is Regression? Regression is a form of predictive modelling technique which helps in creating a relationship between a dependent and independent variable. Types of Regression Linear Regression Logistic Regression Polynomial Regression Stepwise Regression Where is ...

Read More

Difference between various Implementations of Python?

AmitDiwan
AmitDiwan
Updated on 25-Mar-2026 449 Views

Python is a language specification that can be implemented in different ways. Most developers use Python without knowing which specific implementation runs on their system. When we say "Python, " we could mean CPython (the standard implementation), Jython, IronPython, PyPy, or other variants. Each implementation serves different purposes and has unique characteristics. Understanding these differences helps you choose the right Python implementation for your specific use case. CPython CPython is the reference implementation of Python written in C. It's the most widely used Python implementation and what most people simply call "Python." Key Features ...

Read More

Working with PDF files in Python?

Vrundesha Joshi
Vrundesha Joshi
Updated on 25-Mar-2026 1K+ Views

Python provides excellent libraries for working with PDF files. PyPDF2 is a popular pure-Python library that can split, merge, crop, and transform PDF pages. It can also extract text, metadata, and add security features to PDF files. Installation Install PyPDF2 using pip ? pip install PyPDF2 Verify the installation ? import PyPDF2 print("PyPDF2 imported successfully!") PyPDF2 imported successfully! Extracting PDF Metadata You can extract useful information like author, title, subject, and page count from any PDF file ? from PyPDF2 import PdfFileReader def ...

Read More

Junk File Organizer in Python?

Jennifer Nicholas
Jennifer Nicholas
Updated on 25-Mar-2026 644 Views

Organizing files by type can save time when dealing with cluttered directories. This Python script automatically sorts files into appropriate folders based on their extensions and removes empty directories. File Type Configuration First, we define which file extensions belong to each category ? import os from pathlib import Path DIRECTORIES = { "HTML": [".html5", ".html", ".htm", ".xhtml"], "IMAGES": [".jpeg", ".jpg", ".tiff", ".gif", ".bmp", ".png", ".bpg", ".svg", ".heif", ".psd"], ...

Read More

Determine the type of an image in Python?

Nitya Raut
Nitya Raut
Updated on 25-Mar-2026 4K+ Views

In this section, we are going to see how to determine the type of image file programmatically using Python. Consider a situation where you have hundreds of image files in a directory and want to filter specific image formats like JPEG, PNG, or GIF. Python provides the imghdr library to determine the type of an image contained in a file or byte stream. Installation The imghdr module is a standard library package that comes with Python 3.6 and higher installations. However, if you need to install it separately, run the following command ? pip install ...

Read More
Showing 7081–7090 of 61,303 articles
« Prev 1 707 708 709 710 711 6131 Next »
Advertisements