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

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -