About 26,800 results
Open links in new tab
  1. Pure Functions - GeeksforGeeks

    Oct 30, 2023 · Examples of pure functions are strlen(), pow(), sqrt() etc. Examples of impure functions are printf(), rand(), time(), etc. If a function is known as pure to compiler then Loop optimization and subexpression elimination can be applied to it.

  2. What is a Pure Function in Python? | by sanju saini | Medium

    Sep 30, 2024 · Example of a Pure Function. Let’s look at a simple example to see how a pure function works in Python. We’ll write a function that calculates the sum of the squares of two numbers: def...

  3. Pure Functions in Python: A Detailed and Comprehensive Guide

    In this blog, we’ll dive deep into what pure functions are, how they work in Python, their benefits and limitations, practical examples, and strategies for incorporating them into your projects. What is a Pure Function?

  4. Pure functions - PythonInformer

    Sep 11, 2019 · Pure functions attempt to eliminate side effects. The basic definition of a pure function is a function that doesn't cause or rely on side effects. The output of a pure function should only depend on its inputs. There are two basic ways a function can cause side effects that directly affect other parts of the code.

  5. How to check if a function is pure in Python? - Stack Overflow

    Jul 22, 2015 · A pure function is a function similar to a Mathematical function, where there is no interaction with the "Real world" nor side-effects. From a more practical point of view, it means that a pure function can not: Print or otherwise show a message; Be random; Depend on system time; Change global variables; And others

  6. Pure Functions vs Impure Functions in Python. - Medium

    Mar 16, 2022 · A function is not pure if there is something outside the function that can change its return, given the same arguments. Below is an example of a pure function. Given the same arguments,...

  7. Functional Programming in Python - GeeksforGeeks

    Jan 2, 2025 · Pure Functions: These functions have two main properties. First, they always produce the same output for the same arguments irrespective of anything else. Secondly, they have no side-effects i.e. they do modify any argument or global variables or output something. Recursion: There are no “for” or “while” loop in functional languages.

  8. Lesson 14: Writing Pure Functions in Python - Kinda Functional

    Example of a Pure Function. Consider the following Python function that computes the square of a number: def square(n): return n * n This function is pure because it always produces the same output for the same input and does not have any side effects. Impure Functions. In contrast, impure functions can produce different results for the same ...

  9. Pure functions in python

    Feb 22, 2023 · All that a pure function does is return a value(s). It helps keep the code clean and maintainable, as one function will just concisely do one thing without affecting the outer world. Let's move on to digging the handy functions that I mentioned at the start.

  10. A Guide to Functional Programming: Pure Vs Impure Functions

    Jan 11, 2025 · In the code, we define a pure and impure add_to_list function. The pure function modifies a copy of the original input list (my_list), while the impure function does transformations using the original list.

  11. Some results have been removed
Refresh