PHP中有isset方法来检查数组元素是否存在,在Python中无对应函数。 Python的编程理念是“包容错误”而不是“严格检查”。举例如下: Look before you leap (LBYL): if idx len(array): array[idx]else: #handle this Easier to ask forgiveness than permiss
PHP中有isset方法来检查数组元素是否存在,在Python中无对应函数。
Python的编程理念是“包容错误”而不是“严格检查”。举例如下:
Look before you leap (LBYL):
1 2 3 4 |
|
如果不希望看见异常处理,也可以像下面这样:
1 2 3 4 5 6 7 |
|