python: 判斷tuple、list、dict是否爲空的方法

Test

1

2

3

4

5

6

7

8

tuple_test = ()

assert not tuple_test

 

list_test = []

assert not list_test

 

dict_test = {}

assert not dict_test

Summary

根據實驗結果可知,直接通過:

1

if not xxx:

即可判斷 tuple、list、dict 是否 爲空 。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章