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, ∼2562🔥, 0💬
Popular Posts:
Where to find tutorials on Python programming language? I want to learn Python. Here is a large coll...
How to Install Docker Desktop on Windows 10? You can follow this tutorial to Install Docker Desktop ...
How to convert a JSON text string to an XML document with PHP language? Currently, there is no built...
Where to find EPUB Sample Files? Here is a list of EPUB sample files collected by FYIcenter.com team...
How to create a VC# class and build it into a library? If you want to create a VC# class and build i...