Chuỗi kiểm tra Python trống hoặc khoảng trắng

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 ? : No
33

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
34

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
35

 

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
36

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
37
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
0
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
1

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
2
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
0
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
4

 

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
5

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
6
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
7
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
8
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
9
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
0
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
11

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
12
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
7
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
14
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
15
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
0
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
0
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
18
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
19

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
10
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
6____07
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
13
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
14

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
15
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
16

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
10
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
6______07
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
00
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
14

 

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
02

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
6
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
7
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
05
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
9
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
0
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
11

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
12
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
7
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
14
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
332
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
0
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
0
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
18
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
19

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
10
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
6____07
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
13
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
14

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
15
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
16

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
10
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
6______07
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
00
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
14

Đầ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 ? : No
33

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
34

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
351

 

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
36

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
37
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
0
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
1

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
2
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
0
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
4

 

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
5

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
6
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
7
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
8
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
9
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
0
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
11

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
12
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
7____2368
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
369

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
10
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
6
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
7
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
13
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
14

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
15
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
16

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
10
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
6
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
7
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
00
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
14

 

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
02

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
6
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
7
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
05____09
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
0
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
11

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
12
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
7
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
368
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
12

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
10
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
6
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
7
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
13
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
14

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
15
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
16

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
10
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
6
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
7
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
00
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
14

đầ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 ? : No
33

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
34

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
27

 

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
36

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
37
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
0
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
1

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
2
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
0
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
4

 

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
5

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
6
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
7
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
8
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
9
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
0
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
11

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
12
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
7
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
368
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
45
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
46
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
47

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
10
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
6
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
7
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
13
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
14

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
15
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
16

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
10
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
6
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
7
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
00
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
14

 

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
60

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
6
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
7
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
05____09
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
0
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
11

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
12
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
7____2368
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
70
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
46
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
72

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
10
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
6
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
7
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
13
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
14

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
15
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
16

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
10
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
6
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
7
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
00
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
14

đầu ra.   

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
1

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 ? : No
85

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
34

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
87

 

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
36

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
37
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
0
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
1

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
2
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
0
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
4

 

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
5

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
6
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
7
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
8
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
9
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
0
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
11

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
12
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
7
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
368
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
45
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
46
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
368
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
108

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
10
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
6
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
7
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
13
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
14

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
15
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
16

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
10
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
6
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
7
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
00
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
14

 

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
60

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
6
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
7
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
05____09
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
0
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
11

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
12
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
7
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
368
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
70
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
46
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
368
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
134

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
10
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
6
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
7
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
13
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
14

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
15
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
16

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
10
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
6
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
7
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
00
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
14

Đầu ra.
 

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
1

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 ? : No
147
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
0
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
1

The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
150
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
0
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
152
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
153
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
12
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
14
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
156
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
18
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
15
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
159
The zero length string without spaces is empty ? : Yes
The zero length string with just spaces is empty ? : No
160

Làm cách nào để kiểm tra xem một chuỗi có chứa khoảng trắng trong Python không?

Trước tiên hãy kiểm tra xem chuỗi có chỉ chứa khoảng trắng hay không bằng cách sử dụng “hàm isspace()” trong python. Một hàm trả về true nếu có bất kỳ khoảng trắng nào và không có điều lệ nào trong văn bản chuỗi, nếu không, nó sẽ trả về false. Các chuỗi rỗng là "falsy", có nghĩa là chúng được coi là sai trong ngữ cảnh Boolean, vì vậy bạn chỉ có thể sử dụng not string

Làm thế nào để biết nếu một chuỗi chỉ có không gian?

Sử dụng phương thức isspace() bạn có thể lấy kiến ​​thức về chuỗi chỉ có khoảng trắng hay không và đối với chuỗi rỗng, bạn có thể lấy chúng bằng cách sử dụng “not” trong if-else. Trả về True nếu chỉ có các ký tự khoảng trắng trong chuỗi và có ít nhất một ký tự, nếu không thì trả về false

Làm cách nào để kiểm tra xem một chuỗi có trống hay không trong Python?

Bạn có thể kiểm tra xem chuỗi có rỗng hay có khoảng trắng hay không bằng cách sử dụng hàm isspace() và hàm strip() trong python. Bạn cũng có thể chỉ sử dụng not string với câu lệnh điều kiện if-else

Làm cách nào để in một chuỗi rỗng nếu không có khoảng trắng?

Nếu bạn coi khoảng trắng cũng không có trong chuỗi rỗng thì hãy sử dụng phương thức strip(), trong đó phương thức strip() sẽ loại bỏ tất cả khoảng trắng. Vì vậy, nếu chỉ có khoảng trắng thì chuỗi sẽ trống. str1 = " " nếu không str1. dải (). in ("Chuỗi rỗng. ")