header wave

Post

Python) 빈 리스트를 구분할 때

2022-09-20 AM 05/20
#study
#python

지금까지는 len을 이용하여 리스트가 비었을 때 0이 나오는 것을 이용했는데, 간단한 방법이 있었다.

권장하는 방법)
if not seq:
if seq:

권장하지 않는 방법
if len(seq):
if not len(seq):

ex)

if not a:
	print "List is empty"