Question
Which of the following statements about parameter
passing in Python is TRUE?Solution
In Python, arguments are passed to functions using pass-by-object-reference , a hybrid approach where the behavior depends on the object’s mutability. For mutable objects (e.g., lists, dictionaries), functions can modify the object directly, as the reference points to the same memory location. For immutable objects (e.g., integers, strings), any attempt to modify them results in a new object being created, leaving the original object unchanged. For example: def modify_list(lst): lst.append(4) my_list = [1, 2, 3] modify_list(my_list) print(my_list) # Output: [1, 2, 3, 4] In the case of immutables: def modify_int(x): x += 1 num = 5 modify_int(num) print(num) # Output: 5 This illustrates that Python’s approach is neither traditional pass-by-value nor pass-by-reference. Why Other Options Are Incorrect:
- Option A: Python does not strictly follow pass-by-value. Instead, objects are passed as references, which may or may not result in modification based on their mutability.
- Option B: This incorrectly splits the behavior based on mutability. Both mutable and immutable objects are passed by reference; the difference lies in how modifications are handled.
- Option D: This is partially true in terms of scope but does not explain how references to objects work.
- Option E: Functions can indeed modify mutable arguments, as shown in the first example.
Akash Ltd wants to know its ability to meet its short-term obligations towards the various stakeholders. Which category of the following ratios can help...
India’s first Long term Fiscal policy was adopted during the tenure of ..................... as Minister of Finance.
Which of the following methods is most commonly used for predicting patient outcomes in healthcare settings, such as diagnosing diseases or assessing re...
What is a responsibility of businesses in employee relations based on ethical considerations?
If the arithmetic mean is 26.8 and the median is 27.9, then the mode is
Which of the following statements accurately describes the concept of "crowding out" in the context of fiscal policy?
Pradhan Mantri Shram Yogi Maan-Dhan Yojana assures a minimum assured pension of ________ upon attaining the age of 60 years.
Warehouse expense is an example of:
……. Represent the units of currency held and assets and liabilities to be received or paid in a fixed or determinable number of units of currency. <...
The purchase of bonds and shares of Indian companies by Foreign Institutional investors is known as___