Logo

Programming-Idioms

History of Idiom 110 > diff from v105 to v106

Edit summary for version 106 by programming-idioms.org:
[Python] Added Demo URL

Version 105

2023-01-28, 22:21:01

Version 106

2023-02-01, 10:11:27

Idiom #110 Check if string is blank

Set the boolean blank to true if the string s is empty, or null, or contains only whitespace ; false otherwise.

Idiom #110 Check if string is blank

Set the boolean blank to true if the string s is empty, or null, or contains only whitespace ; false otherwise.

Code
blank = not s or s.isspace()
Code
blank = not s or s.isspace()
Comments bubble
not s evaluates to True for None and empty strings.
Comments bubble
not s evaluates to True for None and empty strings.
Doc URL
https://docs.python.org/3/library/stdtypes.html#str.isspace
Doc URL
https://docs.python.org/3/library/stdtypes.html#str.isspace
Demo URL
https://wandbox.org/permlink/eNWjNzfFAO2XXpSX