Sử dụng len[] là phương pháp chung nhất để kiểm tra chuỗi có độ dài bằng không. Mặc dù nó bỏ qua thực tế là một chuỗi chỉ có khoảng trắng cũng thực tế được coi là chuỗi rỗng ngay cả khi nó khác không
Python3
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No33
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No34
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No35
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No36
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No37
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No0
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No1
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No2
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No0
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No4
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No5
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No6
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No7
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No8
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No9
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No0
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No11
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No12
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No7
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No14
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No15
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No0
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No0
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No18
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No19
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No10
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No6____07
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No13
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No14
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No15
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No16
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No10
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No6______07
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No00
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No14
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No02
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No6
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No7
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No05
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No9
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No0
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No11
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No12
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No7
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No14
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No332
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No0
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No0
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No18
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No19
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No10
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No6____07
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No13
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No14
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No15
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No16
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No10
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No6______07
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No00
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No14
Đầu ra.
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No
Phương pháp #2. sử dụng không
toán tử not cũng có thể thực hiện tác vụ tương tự như len[] và kiểm tra chuỗi có độ dài 0, nhưng giống như trên, nó coi chuỗi chỉ có khoảng trắng cũng không trống, điều này thực tế không đúng.
Python3
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No33
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No34
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No351
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No36
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No37
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No0
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No1
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No2
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No0
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No4
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No5
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No6
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No7
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No8
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No9
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No0
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No11
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No12
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No7____2368
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No369
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No10
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No6
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No7
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No13
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No14
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No15
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No16
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No10
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No6
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No7
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No00
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No14
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No02
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No6
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No7
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No05____09
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No0
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No11
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No12
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No7
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No368
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No12
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No10
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No6
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No7
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No13
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No14
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No15
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No16
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No10
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No6
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No7
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No00
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No14
đầu ra.
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No
Phương pháp #3. Sử dụng not + str. dải[]
Vấn đề về chuỗi trống + độ dài bằng 0 có thể được loại bỏ bằng cách sử dụng dải[], dải[] trả về giá trị true nếu nó gặp khoảng trắng, do đó việc kiểm tra nó có thể giải quyết vấn đề kiểm tra chuỗi hoàn toàn trống.
Python3
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No33
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No34
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No27
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No36
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No37
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No0
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No1
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No2
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No0
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No4
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No5
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No6
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No7
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No8
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No9
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No0
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No11
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No12
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No7
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No368
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No45
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No46
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No47
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No10
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No6
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No7
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No13
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No14
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No15
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No16
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No10
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No6
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No7
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No00
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No14
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No60
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No6
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No7
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No05____09
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No0
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No11
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No12
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No7____2368
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No70
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No46
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No72
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No10
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No6
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No7
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No13
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No14
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No15
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No16
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No10
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No6
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No7
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No00
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No14
đầu ra.
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No1
Phương pháp #4. Sử dụng not + str. không gian
Hoạt động theo cách tương tự như phương pháp trên và kiểm tra khoảng trắng trong chuỗi. Phương pháp này hiệu quả hơn bởi vì, dải [] yêu cầu thực hiện thao tác dải cũng cần tải tính toán, nếu không. không gian có số lượng tốt
Python3
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No85
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No34
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No87
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No36
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No37
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No0
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No1
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No2
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No0
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No4
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No5
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No6
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No7
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No8
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No9
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No0
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No11
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No12
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No7
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No368
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No45
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No46
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No368
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No108
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No10
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No6
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No7
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No13
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No14
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No15
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No16
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No10
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No6
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No7
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No00
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No14
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No60
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No6
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No7
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No05____09
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No0
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No11
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No12
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No7
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No368
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No70
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No46
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No368
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No134
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No10
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No6
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No7
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No13
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No14
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No15
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No16
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No10
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No6
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No7
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No00
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No14
Đầu ra.
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No1
Phương pháp. Sử dụng hiểu danh sách
Python3
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No147
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No0
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No1
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No150
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No0
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No152
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No153
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No12
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No14
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No156
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No18
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No15
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No159
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No160