+ 2

what is pure and impure function in python.?

i dont understand the use of impure function. please sight me some examples of it. this will be a great help.

11th Feb 2018, 10:31 AM
Sunny Arya
Sunny Arya - avatar
2 Answers
+ 2
Nothing to do with Python specifically. Pure functions take some arguments by value and return a value. They do nothing else. While impure functions may do anything. Read input, output text to console, write to a file, change variables from surrounding context, change arguments by reference. Basically you can be sure to have pure function, when you do not do input and output and never reassign a variable to a new value.
11th Feb 2018, 12:53 PM
1of3
1of3 - avatar
+ 2
Pure functions are the foundation of the functional paradigm for programming. It is related to the concept of mutability (change) Pure functions are basically those that given an input, will always output the same value. They are not affected by any environment variables. They do not produce changes in nothing that is outside their scope. In a practical way, they can only operate with whatever parameters you give it and any variable that is declared inside the function. Impure functions are the ones based on some external parameter that can mutate (change) and because of this, their output may change at some point of the execution
11th Feb 2018, 3:56 PM
spcan
spcan - avatar