Python Question / Quiz; What is the output of the following Python code, and why? Comment your answers below!

PythonPr's tweet image. Python Question / Quiz; What is the output of the following Python code, and why? Comment your answers below!

Answer:C). 30 Why!? The code first creates an instance of the Rectangle class named rect with a width of 5 and a height of 3. Due to Python's name mangling for attributes starting with __, the __height attribute is stored internally as _Rectangle__height.


Enjoy the best experience on X.


Answer is: c.30 For More Reference =>>

KumarT00623760's tweet image. Answer is: c.30

For More Reference =>>
KumarT00623760's tweet image. Answer is: c.30

For More Reference =>>

width = 10 height = rect._Rectangle__height = 3 area = 10 × 3 = 30


Answer: 15 Because __height is name-mangled, updating rect.__height doesn’t change the original private variable.


I know the answer but i'd rather watch you explain it


Supermicro and NVIDIA enable next-gen AI for federal agencies, optimized for performance, security, and scale. Discover how to accelerate innovation.


Option c


30 Name mangling of __height attribute returns 10*3


Great Share!


Introducing the RevenueCat Figma plugin. Design in Figma → import to RevenueCat → ship instantly. Fully native, ready to A/B test and deploy remotely. No rebuilding designs. No app updates.


United States Tendencias
Loading...

Something went wrong.


Something went wrong.