8
88888 Dihedral
Michael Torrieæ–¼ 2013å¹´6月20日星期四UTC+8下åˆ2時01分11秒寫é“:
Yep, a list is mutable even it's empty.
But constant integers, floats, strings, and None is immutable.
The variables in a function of python with default
parameters which could be mutable or immutable.
def fun1( x, alist=[]):
alist.append(x*x)
return alist ## valid
def fun2(x, alist=None):
if alist==None: alist=[]
alist.append(x*x)
return alist
# kind of boring to show the name binding mechanism of objects
# in Python in different usages
But since the LISP never really got a form beyond S-expressions,
leaving us with lots of parenthesis everywhere, Python wins much as the
Hitchhiker's Guide to the Galaxy wins.
Yep, a list is mutable even it's empty.
But constant integers, floats, strings, and None is immutable.
The variables in a function of python with default
parameters which could be mutable or immutable.
def fun1( x, alist=[]):
alist.append(x*x)
return alist ## valid
def fun2(x, alist=None):
if alist==None: alist=[]
alist.append(x*x)
return alist
# kind of boring to show the name binding mechanism of objects
# in Python in different usages