What argument passing mechanism does python use, and where is this officially documented?

As far as I am aware, python is generally referred to as ‘call-by-sharing’, but does it implement this with call-by-value (like Java) or call-by-reference? or something else? I would appreciate if this could be answered with official python documentation (in which I can’t seem to find the answer) as opposed to anything subjective.

In terms of official documentation, per the Programming FAQ:

Remember that arguments are passed by assignment in Python.

Elsewhere in the docs:

The actual parameters (arguments) to a function call are introduced in the local symbol table of the called function when it is called; thus, arguments are passed using call by value (where the value is always an object reference, not the value of the object).

where the footnote adds:

Actually, call by object reference would be a better description, since if a mutable object is passed, the caller will see any changes the callee makes to it (items inserted into a list).

This is consistent with the rest of Python’s assignment model, for example:

def somefunc(y):
    y.append(1)

x = [0]
somefunc(x)
print x

is similar to:

x = [0]
y = x
y.append(1)
print x

in that the object assigned to the name x is also assigned to the name y (albeit only within somefunc in the former).

You can just ask Python herself:

def is_python_pass_by_value(foo):
    foo.append('More precisely, for reference types, it is call-by-object-sharing.')
    foo = ['Python is pass-by-reference.']

quux = ['Yes, of course, Python *is* pass-by-value!']

is_python_pass_by_value(quux)

print(quux)
# ['Yes, of course, Python *is* pass-by-value!', 'More precisely, for reference types, it is call-by-object-sharing.']

Call-by-sharing is simply a special case of pass-by-value, where the value being passed is an implicit pointer to shared (not necessarily mutable) state.

The semantics of passing and assigning are exactly the same in Python as in Java. Java is described on StackExchange and elsewhere on the Internet (as well as by you in your question) as pass-by-value ony, and these terms must be used consistently across languages to be meaningful; therefore, Python is pass-by-value only.

6

Forget call-by-whathaveyou for Python

Pythons scoping and parameter passing are quite simple
if you do not try to understand them by these
semi-well-defined call-by-X terms.

  • A formal parameter (of a function) is a name.
  • What you pass as the argument to the function represents an object.
  • In the body of the function, that object will be bound to
    that name during function execution.
  • Some objects are mutable (e.g. lists, class objects),
    others are not (e.g. strings, integers).

That’s all there is.

Binding an object to a name (or a name to an object; it’s the same)
is exactly what assignment does:
a = 1 will bind the object 1 to the name a and
a = b will bind the object-that-the-name-b-is-currently-bound-to to the name a.

After def myfunc(a), the call myfunc(b) will bind the name a just like
a = b would, except that the object that b refers to is also brought
to the right scope: the body of myfunc.

See the Python language reference Section
4.1 Naming and Binding.

1

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật