str.isspace [] trả về
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
0 cho chuỗi hợp lệ và trống>>> tests = ['foo', ' ', '\r\n\t', '']
>>> print[[s.isspace[] for s in tests]]
[False, True, True, False]
Do đó, kiểm tra với
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
1 cũng sẽ đánh giá loại >>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
2 và >>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
3 hoặc >>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
4 [chuỗi trống]>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
5>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
6 >>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
The original string is : Geeks forGeeks
Does string contain spaces ? True
1
The original string is : Geeks forGeeks
Does string contain spaces ? True
2
6 >>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
Input : string = 'My name is Ayush'
Output : 3
Input : string = 'My name is \n\n\n\n\nAyush'
Output : 8
0
Cải thiện bài viếtreturns “True” if all characters in the string are whitespace characters, Otherwise, It returns “False”. This function is used to check if the argument contains all whitespace characters, such as:
- Lưu bài viết
- Đôi khi, chúng ta có thể gặp vấn đề trong đó chúng ta cần kiểm tra xem chuỗi có bất kỳ khoảng trống nào không. Loại vấn đề này có thể nằm trong miền học máy để có được loại dữ liệu cụ thể. Hãy để thảo luận về những cách nhất định trong đó loại vấn đề này có thể được giải quyết. Phương pháp số 1: Sử dụng Regex, loại vấn đề này có thể được giải quyết bằng cách sử dụng tiện ích regex do Python cung cấp. Bằng cách cung cấp chuỗi regex thích hợp trong search [], chúng ta có thể kiểm tra sự hiện diện của không gian trong một chuỗi. & Nbsp;
The original string is : Geeks forGeeks Does string contain spaces ? True
3The original string is : Geeks forGeeks Does string contain spaces ? True
4The original string is : Geeks forGeeks Does string contain spaces ? True
5
6>>> tests = ['foo', ' ', '\r\n\t', '', None, ""] >>> print [[not s or s.isspace[] for s in tests]] [False, True, True, True, True, True]
The original string is : Geeks forGeeks Does string contain spaces ? True
7
8>>> tests = ['foo', ' ', '\r\n\t', '', None, ""] >>> print [[not s or s.isspace[] for s in tests]] [False, True, True, True, True, True]
The original string is : Geeks forGeeks Does string contain spaces ? True
9The original string is : Geeks forGeeks Does string contain spaces ? True
0The original string is : Geeks forGeeks Does string contain spaces ? True
13 8
4The original string is : Geeks forGeeks Does string contain spaces ? True
3The original string is : Geeks forGeeks Does string contain spaces ? True
4
6>>> tests = ['foo', ' ', '\r\n\t', '', None, ""] >>> print [[not s or s.isspace[] for s in tests]] [False, True, True, True, True, True]
The original string is : Geeks forGeeks Does string contain spaces ? True
6The original string is : Geeks forGeeks Does string contain spaces ? True
7
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
8The original string is : Geeks forGeeks
Does string contain spaces ? True
93
8
4 >>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
01>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
02
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
Đầu ra: & nbsp;string.isspace[]
Returns:
- Phương pháp số 2: Sử dụng toán tử trong toán tử, tác vụ này cũng có thể được thực hiện bằng toán tử. Chỉ cần kiểm tra một không gian trong chuỗi. Phán quyết được trả lại là đúng ngay cả khi một không gian duy nhất được tìm thấy và sai nếu không. & Nbsp;– If all characters in the string are whitespace characters.
The original string is : Geeks forGeeks Does string contain spaces ? True46>>> tests = ['foo', ' ', '\r\n\t', '', None, ""] >>> print [[not s or s.isspace[] for s in tests]] [False, True, True, True, True, True]
14>>> tests = ['foo', ' ', '\r\n\t', '', None, ""] >>> print [[not s or s.isspace[] for s in tests]] [False, True, True, True, True, True]
Input : string = 'My name is Ayush' Output : 3 Input : string = 'My name is \n\n\n\n\nAyush' Output : 8316– If the string contains 1 or more non-whitespace characters.>>> tests = ['foo', ' ', '\r\n\t', '', None, ""] >>> print [[not s or s.isspace[] for s in tests]] [False, True, True, True, True, True]
Phương thức số 3: Sử dụng phương thức Find [].
Python3
Tìm [] Phương thức Tìm kiếm chuỗi đã cho cho đối số được truyền và trả về vị trí hoặc trả về -1.
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
8>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
9Output:
True
The original string is : Geeks forGeeks
Does string contain spaces ? True
5>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
6 >>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
24
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
8>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
26>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
27 3 84
The original string is : Geeks forGeeks Does string contain spaces ? True3
Python3
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
5>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
6 True2
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
8>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
9>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
5>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
6 True7
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
8>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
9>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
5>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
6 False True False2
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
8False True False4
Output:
False True False
Ví dụ 2: Ứng dụng thực tếApplication
Cho một chuỗi trong Python, đếm số lượng ký tự khoảng trắng trong chuỗi. & NBSP;
Input : string = 'My name is Ayush' Output : 3 Input : string = 'My name is \n\n\n\n\nAyush' Output : 8
Algorithm:
- Đi qua ký tự chuỗi đã cho bằng ký tự lên đến chiều dài của nó, kiểm tra xem ký tự là ký tự khoảng trắng. & NBSP;
- Nếu đó là một ký tự khoảng trắng, hãy tăng bộ đếm 1, khác đi qua ký tự tiếp theo. & NBSP;
- In giá trị của bộ đếm.
Python3
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
5>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
6 False True False7
False True False8
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
6Input : string = 'My name is Ayush' Output : 3 Input : string = 'My name is \n\n\n\n\nAyush' Output : 80
Input : string = 'My name is Ayush' Output : 3 Input : string = 'My name is \n\n\n\n\nAyush' Output : 81
Input : string = 'My name is Ayush' Output : 3 Input : string = 'My name is \n\n\n\n\nAyush' Output : 82
Input : string = 'My name is Ayush' Output : 3 Input : string = 'My name is \n\n\n\n\nAyush' Output : 83
Input : string = 'My name is Ayush' Output : 3 Input : string = 'My name is \n\n\n\n\nAyush' Output : 84
Input : string = 'My name is Ayush' Output : 3 Input : string = 'My name is \n\n\n\n\nAyush' Output : 85
Input : string = 'My name is Ayush' Output : 3 Input : string = 'My name is \n\n\n\n\nAyush' Output : 86
Input : string = 'My name is Ayush' Output : 3 Input : string = 'My name is \n\n\n\n\nAyush' Output : 87
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
6>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
6 3 80
3 81
3 82
False True False8
3 84
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
63 86
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
83 88
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
5>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
6 The original string is : Geeks forGeeks Does string contain spaces ? True1
The original string is : Geeks forGeeks Does string contain spaces ? True2
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
6 Input : string = 'My name is Ayush' Output : 3 Input : string = 'My name is \n\n\n\n\nAyush' Output : 80
Input : string = 'My name is Ayush' Output : 3 Input : string = 'My name is \n\n\n\n\nAyush' Output : 81
Input : string = 'My name is Ayush' Output : 3 Input : string = 'My name is \n\n\n\n\nAyush' Output : 82
Input : string = 'My name is Ayush' Output : 3 Input : string = 'My name is \n\n\n\n\nAyush' Output : 83
Input : string = 'My name is Ayush' Output : 3 Input : string = 'My name is \n\n\n\n\nAyush' Output : 84
Input : string = 'My name is Ayush' Output : 3 Input : string = 'My name is \n\n\n\n\nAyush' Output : 85
Input : string = 'My name is Ayush' Output : 3 Input : string = 'My name is \n\n\n\n\nAyush' Output : 86
Input : string = 'My name is Ayush' Output : 3 Input : string = 'My name is \n\n\n\n\nAyush' Output : 87
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
6>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
6 3 80
3 81
3 82
False True False8
3 84
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
63 86
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
83 88
Output:
3 8
Cải thiện bài viết
Lưu bài viết
Đôi khi, chúng ta có thể gặp vấn đề trong đó chúng ta cần kiểm tra xem chuỗi có bất kỳ khoảng trống nào không. Loại vấn đề này có thể nằm trong miền học máy để có được loại dữ liệu cụ thể. Hãy để thảo luận về những cách nhất định trong đó loại vấn đề này có thể được giải quyết. Phương pháp số 1: Sử dụng Regex, loại vấn đề này có thể được giải quyết bằng cách sử dụng tiện ích regex do Python cung cấp. Bằng cách cung cấp chuỗi regex thích hợp trong search [], chúng ta có thể kiểm tra sự hiện diện của không gian trong một chuỗi. & Nbsp;Method #1 : Using regex This kind of problem can be solved using the regex utility offered by python. By feeding the appropriate regex string in search[], we can check presence of space in a string.
Python3
The original string is : Geeks forGeeks Does string contain spaces ? True3
The original string is : Geeks forGeeks Does string contain spaces ? True4
The original string is : Geeks forGeeks Does string contain spaces ? True5
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
6 The original string is : Geeks forGeeks Does string contain spaces ? True7
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
8The original string is : Geeks forGeeks Does string contain spaces ? True9
The original string is : Geeks forGeeks Does string contain spaces ? True0
The original string is : Geeks forGeeks Does string contain spaces ? True1
3 84
The original string is : Geeks forGeeks Does string contain spaces ? True3
The original string is : Geeks forGeeks Does string contain spaces ? True4
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
6 The original string is : Geeks forGeeks Does string contain spaces ? True6
The original string is : Geeks forGeeks Does string contain spaces ? True7
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
8The original string is : Geeks forGeeks Does string contain spaces ? True9
3 84
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
01>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
02Đầu ra: & nbsp;
The original string is : Geeks forGeeks Does string contain spaces ? True
Phương pháp số 2: Sử dụng toán tử trong toán tử, tác vụ này cũng có thể được thực hiện bằng toán tử. Chỉ cần kiểm tra một không gian trong chuỗi. Phán quyết được trả lại là đúng ngay cả khi một không gian duy nhất được tìm thấy và sai nếu không. & Nbsp; This task can also be performed using in operator. Just required to check for a space in the string. The verdict returned is true even if a single space is found and false otherwise.
Python3
The original string is : Geeks forGeeks Does string contain spaces ? True5
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
6 The original string is : Geeks forGeeks Does string contain spaces ? True7
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
8The original string is : Geeks forGeeks Does string contain spaces ? True9
The original string is : Geeks forGeeks Does string contain spaces ? True0
The original string is : Geeks forGeeks Does string contain spaces ? True1
3 84
The original string is : Geeks forGeeks Does string contain spaces ? True3
The original string is : Geeks forGeeks Does string contain spaces ? True4
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
6 The original string is : Geeks forGeeks Does string contain spaces ? True6
The original string is : Geeks forGeeks Does string contain spaces ? True7
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
8The original string is : Geeks forGeeks Does string contain spaces ? True9
3 84
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
01>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
02Đầu ra: & nbsp;
The original string is : Geeks forGeeks Does string contain spaces ? True
Phương pháp số 2: Sử dụng toán tử trong toán tử, tác vụ này cũng có thể được thực hiện bằng toán tử. Chỉ cần kiểm tra một không gian trong chuỗi. Phán quyết được trả lại là đúng ngay cả khi một không gian duy nhất được tìm thấy và sai nếu không. & Nbsp;.
The original string is : Geeks forGeeks Does string contain spaces ? True4
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
6 >>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
14Input : string = 'My name is Ayush' Output : 3 Input : string = 'My name is \n\n\n\n\nAyush' Output : 83
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
16Python3
Phương thức số 3: Sử dụng phương thức Find [].
Tìm [] Phương thức Tìm kiếm chuỗi đã cho cho đối số được truyền và trả về vị trí hoặc trả về -1.
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
30>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
6>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
0Input : string = 'My name is Ayush' Output : 3 Input : string = 'My name is \n\n\n\n\nAyush' Output : 86
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
34>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
35>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
36>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
6>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
383 86
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
40Input : string = 'My name is Ayush' Output : 3 Input : string = 'My name is \n\n\n\n\nAyush' Output : 85
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
30>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
63 80
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
8>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
26>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
47 3 84
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
01>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
02Đầu ra
The original string is : Geeks forGeeks Does string contain spaces ? True
The original string is : Geeks forGeeks
Does string contain spaces ? True
5
6 >>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
24>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
Python3
Phương thức số 3: Sử dụng phương thức Find [].
Tìm [] Phương thức Tìm kiếm chuỗi đã cho cho đối số được truyền và trả về vị trí hoặc trả về -1.
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
59>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
6Input : string = 'My name is Ayush' Output : 3 Input : string = 'My name is \n\n\n\n\nAyush' Output : 80
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
30>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
6>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
0Input : string = 'My name is Ayush' Output : 3 Input : string = 'My name is \n\n\n\n\nAyush' Output : 81
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
66Input : string = 'My name is Ayush' Output : 3 Input : string = 'My name is \n\n\n\n\nAyush' Output : 83
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
68Input : string = 'My name is Ayush' Output : 3 Input : string = 'My name is \n\n\n\n\nAyush' Output : 85
Input : string = 'My name is Ayush' Output : 3 Input : string = 'My name is \n\n\n\n\nAyush' Output : 86
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
713 82
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
593 84
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
63 86
Input : string = 'My name is Ayush' Output : 3 Input : string = 'My name is \n\n\n\n\nAyush' Output : 86
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
78>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
63 86
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
40Input : string = 'My name is Ayush' Output : 3 Input : string = 'My name is \n\n\n\n\nAyush' Output : 85
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
30>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
63 80
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
8>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
26>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
47 3 84
>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
01>>> tests = ['foo', ' ', '\r\n\t', '', None, ""]
>>> print [[not s or s.isspace[] for s in tests]]
[False, True, True, True, True, True]
02Đầu ra
The original string is : Geeks forGeeks Does string contain spaces ? True