Sarika Singh has Published 137 Articles

How to eliminate repeated lines in a python function?

Sarika Singh

Sarika Singh

Updated on 09-May-2025 15:25:12

6K+ Views

In this article, we will discuss how to delete multiple lines that are repeated in a Python Function. If the file containing the program is small and only has a few lines, we can remove repeated lines manually. However, when dealing with huge files, we need a Python program to ... Read More

How to extract file extension using Python?

Sarika Singh

Sarika Singh

Updated on 07-May-2025 14:01:01

6K+ Views

In a few scenarios, we need to extract the extension of a file to perform specific operations based on its type, such as validating image formats or filtering document files. Python provides different ways to achieve this using the os and pathlib modules. In this article, we'll explore how to ... Read More

How to expand tabs in string to multiple spaces in Python?

Sarika Singh

Sarika Singh

Updated on 07-May-2025 13:13:17

3K+ Views

In Python, handling white spaces between strings is easy. Sometimes, we may want to add space in a string, but we are not sure exactly how much. Python provides different ways to manage this, and one useful method is expandtabs() method. Using the expandtabs() Method The expandtabs() method in Python ... Read More

How do I calculate the date six months from the current date using the datetime Python module?

Sarika Singh

Sarika Singh

Updated on 07-May-2025 12:29:32

3K+ Views

Python does not have a data type for dates, but we may import the datetime module to work with dates as date objects. Calculating dates that are months apart from a given date is quite challenging due to the varying length of months in our calendar system. This article tells ... Read More

Can Python functions run in html as javascript does?

Sarika Singh

Sarika Singh

Updated on 11-Apr-2025 15:31:27

599 Views

Unlike JavaScript, we cannot run Python functions (or scripts) directly in HTML, but we can use tools to make it work. While creating web pages, we use HTML to structure the content and JavaScript to make the page interactive (directly in the browser). We can also write the JavaScript code ... Read More

How to retrieve source code from Python objects?

Sarika Singh

Sarika Singh

Updated on 11-Apr-2025 14:50:14

16K+ Views

Using the inspect module, you can retrieve the source code of a Python function, method, class, or module. The following example demonstrates how to retrieve a function's source code − Example: Retrieve Function Source Code This code defines a simple function my_function(), that accepts two arguments and returns the sum ... Read More

How can we overload a Python function?

Sarika Singh

Sarika Singh

Updated on 11-Apr-2025 14:32:32

4K+ Views

Function overloading means defining multiple functions with the same name but different arguments. This is a built-in feature in many programming languages like C++ or Java. However, in Python, function overloading is not directly supported, but we can achieve it using some techniques. Python uses a concept called dynamic typing, ... Read More

How to write recursive Python Function to find factorial?

Sarika Singh

Sarika Singh

Updated on 11-Apr-2025 10:24:37

1K+ Views

We can write a recursive function in Python to find the factorial of a number. Recursion means that a function calls itself repeatedly to work through different stages of the same task. This technique is useful for tasks that follow a repetitive pattern or have a step-by-step structure like calculating ... Read More

How to list all functions in a Python module?

Sarika Singh

Sarika Singh

Updated on 26-Aug-2023 08:19:02

51K+ Views

In this article we will discuss how to list all the functions in a Python module. A Python module contains multiple different functions that allow for extensive code reusability making complex code simple. It also enhances portability of python program by changing platform dependent code into platform independent APIs Python ... Read More

Python program to find all duplicate characters in a string

Sarika Singh

Sarika Singh

Updated on 26-Aug-2023 08:14:18

40K+ Views

This article teaches you how to write a python program to find all duplicate characters in a string. Characters that repeat themselves within a string are referred to as duplicate characters. When we refer to printing duplicate characters in a string, we mean that we shall print every character, including ... Read More

Advertisements