4 ms·
The undefined.jpg thing won't happen for variables in strict mode, it'll error. [].length is what you want for the second. IIRC [] isn't false in Python either
by TazeTSchnitzel 13y ago
The undefined.jpg thing won't happen for variables in strict mode, it'll error.
[].length is what you want for the second. IIRC [] isn't false in Python either.
- deleted 13y ago[deleted]
- gjm11 13y ago[] is false in Python; so are other empty aggregates like () and {}; collection types implemented in Python typically follow the same pattern. Thus: >>> if (): print "tuple" >>> if []: print "list" >>> if {}: print "dict" >>> if set(): print "set" >>> if "": print "string" >>> import collections >>> if collections.Counter(): print "counter" >>> if collections.deque(): print "deque" >>> (Observe that none of these prints anything.)
- TazeTSchnitzel 13y agoHuh, I recall [] not working. Interesting.
- kevin-brown 13y ago[] is false in Python, along with most empty types. http://ideone.com/ROMcag http://ideone.com/ROMcag