简体   繁体   中英

How do I detect if a bytearray is empty in python?

I need to detect when the bytearray is empty like these two in the middle: 6 个字节数组 2 个空

I am quite new to coding so I have tried this, but it doesnt detect when its for a bytearray:

 if my_bytearray == "":
     print("Read drop out")
if not my_bytearray:
    print("Read drop out")

should work fine.

The mistake in your code is that you compare a bytearray to a string; that is always False . if my_bytearray == b"": would have worked. But the solution above tends to be more Pythonic and more used.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM