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
Articles by Sarika Singh
142 articles
1/4 Mile Calculator using PyQt5 in Python
A 1/4 mile calculator helps estimate how long it takes for a vehicle to cover a quarter-mile (about 400 meters) based on its power and weight. This is commonly used in drag racing to measure a car's acceleration and performance. What Is a 1/4 Mile Calculator? To make this estimation, we use the following basic formula ? ET = (weight / horsepower) ** (1/3) * 5.825 In this formula: ET stands for Estimated Time in seconds Weight is the car's weight in pounds Horsepower is the engine power in HP ...
Read More__getitem__ and __setitem__ in Python
In Python, you can customize many operations like accessing or modifying elements of a list or dictionary using special methods. Two important methods that make your objects behave like lists or dictionaries are: __getitem__: called when you access an item using obj[key]. __setitem__: called when you assign a value using obj[key] = value. These are examples of dunder methods (short for "double underscore"). They are special methods in Python with names that begin and end with double underscores. When you use square bracket syntax on your object: obj[key] automatically triggers __getitem__ obj[key] = value ...
Read More__future__ Module in Python
The __future__ is a built-in Python module that allows you to import features from newer versions of Python into older versions. This enables forward compatibility and helps write code that works consistently across Python versions. What is the __future__ Module? The __future__ module is primarily used when migrating code from Python 2 to Python 3, or when you want to test new language features before they become default in future releases. It ensures your code behaves the same way across different Python versions. For example, in Python 2, dividing two integers returns an integer. By importing the ...
Read More__file__ (A Special Variable) in Python
The __file__ variable in Python is a special attribute that stores the path to the current script or module from which it is accessed. It is automatically set by the Python interpreter when a script is executed or a module is imported. This variable allows you to determine the exact location of the current file, irrespective of where the Python interpreter is run. Understanding __file__ Behavior The value of __file__ can be either a relative path or an absolute path, depending on how the script is executed ? For scripts that ...
Read More__exit__ in Python
In Python, some special methods have names that start and end with double underscores. These are called dunder methods. One such method is __exit__, which is used in context managers for cleanup tasks. Context Manager in Python Context Managers help to manage resources such as files, database connections, or network links. It sets up a temporary environment to run a block of code. When the block ends, Python closes the file or disconnects the connection automatically. This prevents unnecessary resource consumption when we leave a file open or keep a connection (such as network, database) active. ...
Read More__call__ in Python
In Python, everything is treated as an object, including integers, strings, classes, and even functions. It provides a special method named __call__ that allows an instance of a class (i.e. object) to behave like a function (i.e. we can call/invoke it). When we define the __call__ method inside a class, we can call its instance (object) using parentheses, just like a regular function. Syntax Following is the syntax to use the __call__ method inside a class − class MyClass: def __call__(self, *args, **kwargs): ...
Read MoreHow to return a JSON object from a Python function in Tkinter?
JSON (JavaScript Object Notation) is a lightweight data format for exchanging data between different programming languages. In Python, you can work with JSON using the built-in json module, which provides methods to convert Python objects to JSON strings and vice versa. When working with Python functions, you often need to return structured data as JSON objects. This is particularly useful in web applications, APIs, and data processing tasks where standardized data exchange is important. Understanding JSON Conversion Python converts objects to JSON through serialization − the process of transforming Python data structures into a JSON-compatible string format. ...
Read More1-bit and 2-bit Characters in Python
In computers, everything is stored in the form of bits, i.e., the smallest pieces of data that can be either 0 or 1. When we talk about 1-bit or 2-bit characters, we mean how many of these bits are used to make a single character (like a letter or symbol). A 1-bit character is just a single 0. It counts as one character by itself. A 2-bit character is made of two bits and can be either 10 or 11. If we are given a list of bits (containing only 0s and 1s) that ends with ...
Read MoreData Hiding in Python
Data hiding is also known as data encapsulation and it is the process of hiding the implementation of specific parts of the application from the user. Data hiding combines members of class thereby restricting direct access to the members of the class. Data hiding plays a major role in making an application secure and more robust. Data Hiding in Python Data hiding in Python is a technique of preventing methods and variables of a class from being accessed directly outside of the class in which the methods and variables are initialized. Data hiding of essential member functions ...
Read MorePython Program for Detect Cycle in a Directed Graph
A cycle occurs when a path starts and ends at the same vertex, following the direction of the edges. In directed graphs, cycles can cause problems like infinite loops or dependency errors, so detecting them is important in areas like task scheduling and deadlock detection. We can use Depth-First Search (DFS) with a recursion stack to detect whether a cycle exists in a directed graph or not. Problem Statement You are given a directed graph represented using an adjacency list. Your task is to write a Python program to check whether the graph contains a cycle or ...
Read More