# CodeStepByStep

## functional_concepts

Language/Type: Python functional programming

Answer the following questions about functional programming. The third question refers to the following function `double_all`:

```# Doubles the values of all elements in a list.
def double_all(a):
for i in range(len(a)):
a[i] = 2 * a[i]
```

The xth questionrefers to the following lambda code:

```a = 1
b = 2
lambda b, c: c + b - a
```
 Why do functional programmers want to avoid side effects? Functions without side effects are easy to reason about, reuse, combine, and parallelize. A side effect makes a function unable to be understood by the programmer. Side effects are bugs that should never occur. Side effects make a function run more slowly. (order shuffled) Which of the following would be considered a side effect? (Check all that apply.) Returning a value. Writing data to a file. Producing console output with the print() function. Modifying a parameter value by reference, such as a list. Modifying the value of a global variable. (order shuffled) What side effect does the double_all function have? It is not allowed to have a loop. It modifies the list that was passed in. Calling the range() function produces a side effect. It does not print the list at the end. (order shuffled) What is the difference between a free variable and a bound variable? A bound variable is inside the lambda, and a free variable is declared outside the lambda. They are the same. A bound variable is constant and a free variable can be changed. A bound variable is a simple type like int, and a free variable is an object. A bound variable is out of scope in a function. (order shuffled) What are the free variables in the lambda function in the code? (Check all that apply.) ``` a ``` ``` b (first one) ``` ``` b (second one) ``` ``` c ``` ``` none of the above ``` What are the bound variables in the lambda function in the code? (Check all that apply.) ``` a ``` ``` b (first one) ``` ``` b (second one) ``` ``` c ``` ``` none of the above ```