Tools, FAQ, Tutorials:
Function Parameters Assigned with Object References
Is it true that all function parameters are assigned with object references in Python?
✍: FYIcenter.com
Yes, all function parameters are assigned with object references in Python. You modify referenced data objects to share data with the calling statement.
Here is a good example of modifying the data object referenced by the parameter:
IndentationError: unexpected indent >>> def load(name,age,user): ... profile = {"name":name,"age":age} ... user["profile"] = profile ... >>> guest = {} >>> load("Joe",25,guest) >>> guest {'profile': {'name': 'Joe', 'age': 25}}
Note that both variables "guest" and "user" are referring to the same data object.
⇐ Variable Scope in Function Definition Statements
2018-02-08, 1474🔥, 0💬
Popular Posts:
How to use urllib.parse.urlencode() function to encode HTTP POST data? My form data has special char...
How to search for the first match of a regular expression using re.search()? The re.search() functio...
How To Move Uploaded Files To Permanent Directory in PHP? PHP stores uploaded files in a temporary d...
Why I am getting "The Windows SDK version 8.1 was not found" error, when building my C++ application...
How To Read a File in Binary Mode in PHP? If you have a file that stores binary data, like an execut...