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 ? : 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 ? : No3
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No4_______0_______5 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 ? : No7The 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 ? : No9
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes0
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes2The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes3The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes4The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes6
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes7_______10_______2The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes9The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes0The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No5The 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 ? : Yes3The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes4
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes2The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes8The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes9
['yes']0_______30_______1
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes2['yes']5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes9
['yes']7
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes2The string is empty.0The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes4The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes6
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes7_______10_______2The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes9The string is empty.7The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No5The 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 ? : Yes3The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes4
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes2The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes8The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes9
['yes']0_______30_______1
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes2['yes']5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes9
Đầu raThe 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 ? : No0
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No1
string, string1 = '', with no spaces is empty string, string2 = ' ', with spaces is empty6
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No3
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No4_______0_______5 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 ? : No7The 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 ? : No9
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes0
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes2_______10_______3The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes4_______0_______5 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes6
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes7_______10_______2string, string1 = '', with no spaces is empty string, string2 = ' ', with spaces is empty3 string, string1 = '', with no spaces is empty string, string2 = ' ', with spaces is empty4
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes2The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes8_______10_______9
['yes']0 ['yes']1
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes2['yes']5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes9
['yes']7
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes2_______40_______0The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes4The 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 ? : Yes6
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes7_______10_______2string, string1 = '', with no spaces is empty string, string2 = ' ', with spaces is empty3 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No17
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes2The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes8_______10_______9
['yes']0 ['yes']1
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes2['yes']5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes9
Đầu raThe 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ề 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 ? : 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 ? : No32
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No3
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No4_______0_______5 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 ? : No7The 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 ? : No9
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes0
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes2_______10_______3The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes4_______0_______5 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes6
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes7_______10_______2string, string1 = '', with no spaces is empty string, string2 = ' ', with spaces is empty3 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No50The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No51 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No52
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes2The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes8_______10_______9
['yes']0 ['yes']1
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes2['yes']5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes9
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No65
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes2_______40_______0The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes4The 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 ? : Yes6
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes7_______10_______2string, string1 = '', with no spaces is empty string, string2 = ' ', with spaces is empty3The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No75The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No51 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No77
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes2The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes8_______10_______9
['yes']0 ['yes']1
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes2['yes']5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes9
Đầu raThe zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes
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 ? : No90
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 ? : No92
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No3
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No4_______0_______5 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 ? : No7The 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 ? : No9
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes0
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes2_______10_______3The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes4_______0_______5 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes6
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes7_______10_______2string, string1 = '', with no spaces is empty string, string2 = ' ', with spaces is empty3 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No50The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No51 string, string1 = '', with no spaces is empty string, string2 = ' ', with spaces is empty3 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes13
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes2The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes8_______10_______9
['yes']0 ['yes']1
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes2['yes']5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes9
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No65
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes2_______40_______0The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes4The 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 ? : Yes6
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes7_______10_______2string, string1 = '', with no spaces is empty string, string2 = ' ', with spaces is empty3 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No75The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No51 string, string1 = '', with no spaces is empty string, string2 = ' ', with spaces is empty3 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes39
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes2The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes8_______10_______9
['yes']0 ['yes']1
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes2['yes']5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes9
Đầu raThe zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes
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 ? : Yes52_______0_______5The 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 ? : Yes55The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes57The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes58 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes7 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes9The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes61The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes3 ['yes']0 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes64The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes65
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes67
Đầu ra['yes']
Phương pháp. Sử dụng bool
Một cách tiếp cận là sử dụng hàm bool. Hàm bool trả về Sai cho chuỗi rỗng và True cho chuỗi không trống
Đây là một ví dụ về việc sử dụng hàm bool để kiểm tra xem một chuỗi có rỗng hay không
Python3
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes68
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes69_______0_______5 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 ? : Yes72
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes7 string, string1 = '', with no spaces is empty string, string2 = ' ', with spaces is empty3 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes75The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes76
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes2The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes80The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes9
['yes']0_______30_______1
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes2The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes87The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes9
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes89
Đầu raThe string is empty.
Bạn cũng có thể sử dụng hàm bool để kiểm tra xem một chuỗi có trống hay không sau khi xóa mọi khoảng trắng ở đầu hoặc cuối bằng phương thức dải
Python3
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes68
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes69_______0_______5 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 ? : Yes94
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes7 string, string1 = '', with no spaces is empty string, string2 = ' ', with spaces is empty3 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes75The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes98
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes2The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes80The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes9
['yes']0_______30_______1
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes2The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes87The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes9
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes89
Đầu raThe string is empty.
Phương pháp. sử dụng dải
Python3
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes12
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes13The 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 ? : Yes15
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes16 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 ? : Yes18
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes19
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes7 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes21
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes24The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes25The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes26
['yes']0_______10_______28
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes24The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes32The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes26
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes34
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes7 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes16The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes37
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes24The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes41The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes26
['yes']0_______10_______28
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes24The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes48The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes26
Đầu rastring, string1 = '', with no spaces is empty string, string2 = ' ', with spaces is empty
Phương pháp. Sử dụng phương thức __eq__
Python3
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes50
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes51______0_______5 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes15
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes54____0_______5 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes56
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes19
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes7 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes59
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes24The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes63The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes26
['yes']0_______10_______28
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes24The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes70The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes26
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes34
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes7 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes74
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes24The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes78The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes26
['yes']0_______10_______28
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes24The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes85The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes26
Đầu rastring, string1 = '', with no spaces is empty string, string1 = ' ', with no spaces is not empty
Phương pháp. Sử dụng toán tử “and” + hàm strip()
Python3
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes12
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes51______0_______5 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes15
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes54____0_______5 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes18
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes19
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes7 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes51The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No51 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes98
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes24The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes70The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes26
['yes']0_______10_______28
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes24The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes63The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes26
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes34
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes7 The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes54The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : No51 ['yes']15
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes24['yes']19The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes26
['yes']0_______10_______28
The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes5The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes1The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes24['yes']26The zero length string without spaces is empty ? : Yes The zero length string with just spaces is empty ? : Yes26
Đầu rastring, string1 = '', with no spaces is empty string, string2 = ' ', with spaces is empty
Phương pháp “bool” để kiểm tra xem một chuỗi có rỗng hay không có độ phức tạp về thời gian là O(1), vì nó chỉ đơn giản kiểm tra giá trị thực của chuỗi, đây là một phép toán thời gian không đổi. Không gian phụ cũng là O(1) vì nó chỉ yêu cầu một biến boolean duy nhất để lưu trữ giá trị thực của chuỗi