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
'Inactive Board' 카테고리의 다른 글
[Python] Three Methods to Reverse a List (0) | 2024.12.06 |
---|---|
[Python] 파이썬의 전달 방식은 값 전달? 참조 전달? (0) | 2024.12.03 |
[Python] 백준 11718번: EOFError가 발생하지 않는다고? (0) | 2024.11.23 |
[Python] BOJ 11718: No input values, No EOFError? (0) | 2024.11.22 |
[Python] 연결리스트: 노드가 주소를 가리킨다고? (1) | 2024.11.12 |