4 ms·
They're shadowing builtins. Python's list type can't be referenced by its name in the defined sum function and Python's sum function can't be used in or after
by fucking_tragedy 10y ago
They're shadowing builtins. Python's list type can't be referenced by its name in the defined sum function and Python's sum function can't be used in or after the new function's definition.
One could argue that in a source meant to teach Python, it shouldn't use examples that don't follow best practices. I feel that as a resource to, from the page, "learn how to write code, the basics and see examples" that it doesn't really matter too much.
- scrapcode 10y agoI learned to program in PHP and builtins tripped me up a LOT as a new programmer. Talk about wrapping your head around some things when you're brand new.
- ATsch 10y agoI thought GP's issue was that the function is shadowing itself within itself, which I think is worse than shadowing a builtin with a similar function.
- fucking_tragedy 10y agoI had completely missed that one. That is pretty bad and confusing.
- wlesieutre 10y agoAnd using "list", which IIRC is a reserved keyword
- sporkologist 10y agoThis kind of thing leads to many "wait, what?" moments... confusing and aggravating to someone just learning syntax.