Sarika Singh has Published 189 Articles

What is an anonymous function in Python?

Sarika Singh

Sarika Singh

Updated on 11-Apr-2025 19:18:04

22K+ Views

Anonymous Function in Python An anonymous function is a function which doesn't have a name. We can return a value from an anonymous function, call it at the time of creation or, assign it to a variable. Instead of using the def keyword, which is used for regular functions, anonymous ... Read More

Can Python functions run in html as javascript does?

Sarika Singh

Sarika Singh

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

407 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 use a global variable in a Python function?

Sarika Singh

Sarika Singh

Updated on 11-Apr-2025 14:55:53

4K+ Views

We can use a global variable inside a Python function by declaring it using the global keyword. This allows us to read or modify a variable that is defined outside the function's local scope. By default, any variable you create or change inside a function is considered a local variable ... Read More

How to retrieve source code from Python objects?

Sarika Singh

Sarika Singh

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

15K+ 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 to pass Python function as a function argument?

Sarika Singh

Sarika Singh

Updated on 11-Apr-2025 14:43:30

28K+ Views

We can pass a Python function as a function argument by treating it like any other object. In Python, functions are first-class objects. This means you can treat them like any other value, assign them to variables, return them from other functions, and even pass them as arguments to other ... 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 can we create recursive functions in Python?

Sarika Singh

Sarika Singh

Updated on 11-Apr-2025 14:30:18

4K+ Views

Recursion is a process where a function calls itself repeatedly with new input values, slowly moving toward a condition where it stops. This stopping condition is called the base case. It prevents the function from running endlessly and allows it to return a final result. In Python, we can create ... 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

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