1 1 vote What is the output of the following Python code? x = 5 def outer(): x = 10 def inner(): global x x += 1 inner() return x print(outer(), x)$105$ $116$ $106$ $115$ Programming in Python goclasses python-&-dsa goclasses-da-dpp goclasses-da-dpp-day-81 goclasses-python-&-dsa-practice-questions + – GO Classes 186 views answer comment Share Follow Print 0 reply Please log in or register to add a comment.
0 0 votes Inside $\verb|outer()|$, a local variable $\verb|x|$ is created and set to $\verb|10|$.Inside $\verb|inner()|$, the $\verb|global x|$ statement tells Python to use the $\verb|x|$ defined at the top level $($which is $\verb|5|)$, not the $\verb|x|$ in $\verb|outer()|$.$\verb|inner()|$ increments the global $\verb|x|$ to $\verb|6|$.When $\verb|outer()|$ returns $\verb|x|$, it returns its own local $\verb|x|$, which is still $\verb|10|$.The final print statement outputs the returned local value $(\verb|10|)$ and then the updated global value $(\verb|6|)$. GO Classes answered Jan 6 GO Classes comment Share Follow 0 reply Please log in or register to add a comment.