Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
检查字符串是否只有白色字符(如 \r \t \n " ")的最简单方法是什么?
isspace()字符串方法告诉你:
isspace()
>>> " ".isspace() True >>> " x ".isspace() False
另一种选择是剥去末端:
if not s.strip(): print "It was all whitespace!"