Python built-in type as function parameter -
this question has answer here:
i've decided coding exercises @ coderbyte.com , right in first exercise (reverse string) found this:
def firstreverse(str):
even though works, don't think it's idea use built-in type name parameter. think? know it's kinda silly, it's first question @ stackoverflow! =)
in function definition, str
supposed string
, not built-in function str()
. when this, overwriting built-in function, won't able call str()
inside function f
, can still using outside. because scoping, overwriting in local scope of f
:
def f(str): print str(123) # raise error, because 'str' not callable (i.e. function) anymore f("some string here") print str(123) # ok
this common mistake, sooner learn avoid it, sooner become programmer.
Comments
Post a Comment