0
越来越整数输入我知道我们能同时获得字符串输入使用此跳过任何数量的空行:如何忽略空行,而在Python 2.7
words = raw_input()
while words in ('\n' or '\r\n'):
words = raw_input()
会是怎样做同样的程序,如果输入是整数类型?
越来越整数输入我知道我们能同时获得字符串输入使用此跳过任何数量的空行:如何忽略空行,而在Python 2.7
words = raw_input()
while words in ('\n' or '\r\n'):
words = raw_input()
会是怎样做同样的程序,如果输入是整数类型?
如果前面和尾部空格是没有意义的,我建议.strip()
相结合的方法,并检查真实性(如空字符串是falsy)
words = raw_input()
while not words.strip():
words = raw_input()
如果给出的输入字符串是空行或整数,这将要求输入新的输入。
words = raw_input()
while words in ['\n','\r\n'] or words.isdigit():
words = raw_input()
OR
这将要求新的输入,如果给定的输入字符串为整数。
words = raw_input()
while words.isdigit():
words = raw_input()
你可以用一个例子澄清你的问题?您的标题看起来与内容不同。 – Joost 2015-04-03 07:14:39
'('\ n'或'\ r \ n')'不符合您的想法。 – 2015-04-03 07:29:29