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 是否 为空 。

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