Which statement is NOT True about functions in Python? We can write our own func
ID: 3664275 • Letter: W
Question
Which statement is NOT True about functions in Python?
We can write our own functions.
A function either returns a value or has side-effect(s), but not both.
We make use of the keyword def to define a function.
Function body does not get to execute until the function is called.
a.We can write our own functions.
b.A function either returns a value or has side-effect(s), but not both.
c.We make use of the keyword def to define a function.
d.Function body does not get to execute until the function is called.
Explanation / Answer
B)A function either returns a value or has side-effect(s), but not both is not true
Side effects
In mathematics, a function maps one or more input values to some output value. In computer programming, many functions fit that same model: they accept one or more arguments, and their only purpose is to return a value. A pure function is a function that, given the same arguments, always return the same value, without producing any observable side effects, such as consuming input, producing output, or otherwise changing the state of the system. So far, in this section we have considered only pure functions.
However, in computer programming it is also useful to define functions that do produce side effects. In fact, we often define functions whose only purpose is to produce side effects. An explicit return statement is optional in such a function: control returns to the caller after Python executes the function’s last statement. Functions with no specified return value actually return the special value None, which is usually ignored.
For example, the stdio.write() function has the side effect of writing the given argument to standard output (and has no specified return value). Similarly, the following function has the side effect of drawing a triangle to standard drawing (and has no specified return value):
It is generally poor style to compose a function that both produces side effects and returns a value. One notable exception arises in functions that read input. For example, the stdio.readInt() function both returns a value (an integer) and produces a side effect (consuming one integer from standard input).
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.