Python Question / Quiz; What is the output of the following Python code, and why? 🤔🚀 Comment your answers below! 👇 #python #programming #developer #programmer #coding #coder #softwaredeveloper #computerscience #webdev #webdeveloper #webdevelopment #pythonprogramming

Python_Dv's tweet image. Python Question / Quiz;

What is the output of the following Python code, and why? 🤔🚀 Comment your answers below! 👇

#python #programming #developer #programmer #coding #coder #softwaredeveloper #computerscience #webdev #webdeveloper #webdevelopment #pythonprogramming…

:-B Since no argument is passed, the default list x=[] is used The function appends 1 to this list [1] The function returns the modified list [1] print(foo()) outputs [1]. 2: foo(): This list is now [1] The function appends another 1 to the list [1, 1] output[1,1] [1], [1,1]


Stream, call, game, and work in even the most remote locations. Order online in minutes


This illustrates a pitfall to avoid when using mutable types as parameters.


A will be the correct one!


B is the right answer Because when function is called for the first time, 1 is appended to it means x=[1] already has this when we call it for the second time.


Because x is declared outside of the function. Makes sense. Unlikely to occure during runtime tho


A


Enterprise grade phone system from 3CX. Cut licensing costs by 80% with no per user pricing. Easy set up, DIY admin, cut call costs and choose where to host. 3CX is the PBX of choice for 350,000 installs and counting.


B, conforme a função é executada vai sendo adicionado 1 na lista


It definitely should be [1] [1,1] cause when you use a list as a default value or argument for a parameter it retains memory for each call of the function.


United States Trends
Loading...

Something went wrong.


Something went wrong.