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 Show Python3The 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. Python3The 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. Python3The 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 Python3The 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áchPython3The 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 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. ") |