3 ms·
Python totally has more than one way to do it. People sometimes simplify the python approach as 'the opposite of the perl approach', but they're not exactly opp
by drewp 19y ago
Python totally has more than one way to do it. People sometimes simplify the python approach as 'the opposite of the perl approach', but they're not exactly opposites.
The philosophy that makes python distinct is "There should be one-- and preferably only one --obvious way to do it." Emphasize the word 'obvious' if you don't see why this isn't the same as "There is only one way to do it".
Python has many redundant mechanisms: def/lambda, list.append/list.extend, sys.exit/SystemExit, x[y]/getattr(x,y), etc. But even though multiple mechanisms exist, the hope is that there will be a single obvious way to do whatever you want at the moment. Want to add one element to a list? list.append. Want to add another sequence to a list? list.extend. (The point here is that list.extend would be technically sufficient for both cases, but it makes the one-element case clunkier and less obvious.)
A language where there was actually only one way to get a particular result might be interesting, but it wouldn't look like python.