Computer Science, asked by incharapatel99, 3 months ago

What is the output of the following Python code:
test = [0, 1, 2]
def increment(x):
return X+2
print(list(map(test, increment)))​

Answers

Answered by jai696
1

\huge{\mathtt{{\blue{\boxed{\tt{\pink{\orange{A}\purple{n}\blue{s}\red{w}\green{e}\pink{r᭄}}}}}}}}

It will throw an error as the code is incorrect.

\huge\blue{\mid{\fbox{\tt{Explanation}}\mid}}

Corrected code

test = [0, 1, 2]

def increment(x):

return X+2

print(list(map(increment, test)))

It will output [2, 3, 4] as map function will apply the increment function to each item in test list.

You don't need a function for something this trivial, you can make it inline like this.

test = [0, 1, 2]

print(list(map(lambda x: x + 2, test)))

\large\mathsf\color{lightgreen}useful?\: \color{white}\longrightarrow\: \color{orange}brainliest!

Similar questions