Sarika Singh

Sarika Singh

142 Articles Published

Articles by Sarika Singh

Page 15 of 15

How to write recursive Python Function to find factorial?

Sarika Singh
Sarika Singh
Updated on 11-Apr-2025 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 factorials, generating the Fibonacci series, or navigating tree structures (tree traversal). The factorial of a number is the product of all positive integers from 1 to that number. It is represented using the symbol n! and defined as - n! = n X (n - 1) X (n - 2) ...

Read More

Can we explicitly define datatype in a Python Function?

Sarika Singh
Sarika Singh
Updated on 13-Feb-2020 934 Views

Yes, in Python, you can explicitly define the datatype of function parameters and return values using type hints or type annotations. Even if you specify the data types using type hints, Python will still run the code even when the wrong types are passed. The execution of the program will not be interrupted, and an error will not be raised.To find these type-related mistakes, you can use tools like mypy or pyright that check your code before it runs. Using Type Hints in Python Functions To add type hints to a parameter of a function, you need to specify the ...

Read More
Showing 141–142 of 142 articles
« Prev 1 11 12 13 14 15 Next »
Advertisements