How?
To begin with, the correct answer is that python's parameter passing mechanism is call by assignment. It is also referred to as call by object-reference or call by sharing, all of which mean the same thing. In Python, when a function is called, the argument is passed as a reference to the object.
To help understand this, consider that data types like int or str are immutable objects, so even if you try to change their values within a function, the original object will not be affected. On the other hand, for mutable objects like list or set, if you try to modify them inside a function, the original object will also be changed. In other words, it can be understood as a mix of call by value and call by reference.
Object Reference Passing
For immutable objects → call by value
For mutable objects → call by reference
'OLD > Legacy' 카테고리의 다른 글
| [Python] Three Methods to Reverse a List (1) | 2024.12.06 |
|---|---|
| [Python] 파이썬의 전달 방식은 값 전달? 참조 전달? (2) | 2024.12.03 |
| [GitHub] 최근 커밋 완전히 삭제하기 (1) | 2024.11.30 |
| [GitHub] Deleting the Most Recent Commit (2) | 2024.11.29 |
| [DS] 스택, 큐, 덱 (1) | 2024.11.26 |