1. 程式人生 > >Python中判斷Nonetype的方法

Python中判斷Nonetype的方法

轉載請註明出處:http://blog.csdn.net/dongdong9223/article/details/85339387
本文出自【我是幹勾魚的部落格

Ingredients:

python中出現:

TypeError: ‘NoneType’ object is not subscriptable

的錯誤時說明需要進行判斷,而對 ‘NoneType’ 進行判斷時直接使用‘is None’即可,如下:

if text is None:
    print
('test is ' + None) else: print('test is not ' + None)

參考:

Python中的Nonetype型別怎麼判斷