Pure Functions and Non-Pure Functions in Python | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
+ 1

Pure Functions and Non-Pure Functions in Python

What is the difference between pure and non-pure functions in python?

4th Feb 2019, 1:59 PM
Onteri
Onteri - avatar
2 ответов
+ 3
A pure function is like a "mathematical" function, i.e. given some arguments it will always produce the exact same result, regardless of global state. It will do no I/O, no network communication, no other effect apart from returning a value. This also includes not messing with parameters passed by reference (or pointer). Non-pure - all the rest. E.g. logging something, writing to a file, basically anything visible from the outside, apart from the return value.
4th Feb 2019, 2:40 PM
Ray
+ 3
Pure function means that your function only uses the values you pass as arguments and only gives back the return value but doesn't change anything else outside of the function. This makes it easier to find bugs.
4th Feb 2019, 3:00 PM
HonFu
HonFu - avatar