[New-bugs-announce] [issue22511] Assignment Operators behavior within a user-defined function and arguments being passed by reference or value
Mohammed Mustafa Al-Habshi
report at bugs.python.org
Sun Sep 28 17:26:49 CEST 2014
New submission from Mohammed Mustafa Al-Habshi:
hello every one,
I was trying to understand the behavior of passing arguments in a function to differentiate how we can pass argument by value. Though it is a technique matter. However, the behavior of assignment operator +=
when using it with a list is more to toward behavior to the "append" method of the list object, and not like a a normal assignment.
This causes a confusing when teach python language concepts , especially the behavior of += with numerical data types is list normal assignment and the parameters are then passed by value.
The issue is more related to data type mutability. and I believe assignment operator should be synthetically more compatible with normal assignment.
---- inline code example -----
def pass_(x):
# x is list type
print "Within the function"
print " x was " , x
#x = x + [50] # here x is passed by value
x += [50] # here x is passed by reference.
#x.append(50) # here x is passed by reference.
print " x then is " , x
return
x = [12,32,12]
pass_(x)
print "\n x out of the function is " , x
----------
messages: 227761
nosy: alhabshi3k
priority: normal
severity: normal
status: open
title: Assignment Operators behavior within a user-defined function and arguments being passed by reference or value
type: behavior
versions: Python 2.7
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue22511>
_______________________________________
More information about the New-bugs-announce
mailing list