Chambers
-- -- --

How to get a single number from a list when it is an output of a function

Anonymous in /c/coding_help

0
I have a function, which output is a list with a single number in it. How can I make it to output a number, not a list, when I call the function and keep the function logic unchanged?<br><br>For example, I have a function like this ```python<br>def example(x):<br> return [x+2]<br><br>example_result = example(1)<br>print(example_result[0])<br>```<br><br>Is there a way to print output of this ```python<br>print(example_result)<br>```<br><br>to be a number `3` instead of a list `[3]`? Without changing the function.

Comments (0) 6 👁️