本篇介紹如何在 Python 檢查 str 字串是否為空,
使用 not operator 運算子
使用 not operator 運算子來檢查 str 字串是否為空,
同時也是官方推薦的作法,
1 | #!/usr/bin/env python3 |
結果輸出:
1 | <class 'list'> |
使用 len 判斷長度
使用 len()
函式來檢查 str 字串是否為空,
1 | #!/usr/bin/env python3 |
結果輸出:
1 | <class 'str'> |
其它相關文章推薦
如果你想學習 Python 相關技術,可以參考看看下面的文章,
Python 新手入門教學懶人包
Python str 字串用法與範例