怎么样:
s = sb and sb.ToString()
如果sb为Falsy,则短路的布尔值停止,否则返回下一个表达式。
顺便说一句,如果获取None不重要…
sb = ""#we wont proceed to sb.toString, but the OR will return None here...s = (sb or None) and sb.toString()print s, type(s)
输出:
None <type 'NoneType'>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)