General computer language, syntax question.

Steven D'Aprano steve at pearwood.info
Tue Mar 1 06:42:22 EST 2016


On Tue, 1 Mar 2016 12:56 am, jonas.thornvall at gmail.com wrote:

> I mean for for example Javascript

Jonas, this is a Python forum. If we thought Javascript was a beautiful and
well-designed language, we're be on a Javascript forum, complaining about
Python.


> if (typeof array[index] !== 'undefined' && array[index] !== null) {
> or this one
> if (array[index] != null) {
> 
> I mean how do they come up with such convoluted syntax, do they pull it
> out of ass? 

Probably. I don't know Javascript very well. It is possible that your
statements about Javascript are as misinformed as your statements about
Python.


In Python, you certainly can do membership testing of a list:

py> alist = ["ab", "cd", "ef", "gh"]
py> "ef" in alist
True
py> "xy" in alist
False


and you can also test for empty lists just as easily:

py> if alist:
...     print("not empty")
... else:
...     print("empty")
...
not empty

py> blist = []
py> if blist:
...     print("not empty")
... else:
...     print("empty")
...
empty




-- 
Steven




More information about the Python-list mailing list