Sarika Singh has Published 189 Articles

What are the basic scoping rules for python variables?

Sarika Singh

Sarika Singh

Updated on 12-May-2025 11:30:20

540 Views

In Python, scoping rules define where you can access or modify a variable in your code. It is important to understand these rules because using a variable in the wrong place can cause errors or unexpected results. Python follows a specific order to find a variable, called the LEGB rule. ... Read More

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 we can store Python functions in a Sqlite table?

Sarika Singh

Sarika Singh

Updated on 07-May-2025 16:33:25

268 Views

In Python, you can store a function as a text string in a SQLite database using the sqlite3 module. You cannot run the function directly from the database, but you can retrieve the code later and execute it using Python's exec() or eval() functions. This is helpful when you want ... 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

Which is more fundamental between Python functions and Python object-methods?

Sarika Singh

Sarika Singh

Updated on 07-May-2025 12:51:58

205 Views

In Python, both functions and object methods are used to organize and reuse code, but they have different purposes. To understand which is more fundamental requires understanding how each one works and their roles in Python programming. A function in Python is a block of reusable code that performs a specific ... 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

2K+ 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

Why would you use the return statement in Python?

Sarika Singh

Sarika Singh

Updated on 06-May-2025 10:57:21

3K+ Views

The return statement in Python is used to return a value or a set of values from a function. When a return statement is encountered in a function, the function execution is stopped, and the value specified in the return statement is returned to the caller. Without it, a function ... Read More

How can a Python function return a function?

Sarika Singh

Sarika Singh

Updated on 14-Apr-2025 15:45:33

18K+ Views

In Python, functions are treated as first-class objects, which means that all functions in Python are treated like any other object or variable. You can assign a function to a variable, pass it as an argument to another function, return it from a function, or even store it in data ... Read More

How to use Lambda Function in Python?

Sarika Singh

Sarika Singh

Updated on 14-Apr-2025 15:39:42

3K+ Views

Lambda Function in Python Lamda functions are inline functions, i.e., functions that are written in a single line instead of using multiple lines. These are anonymous functions (functions without a name). We can define a lambda function using the lambda keyword. These are typically used when we need to return ... Read More

Advertisements