2015-02-11 20 views

回答

0

以下提供了在python 2(以及輸入在python 3)使用的raw_input:

>>> inp = raw_input("Enter space separated values of form 'a b 2 5' \n") 
Enter space separated values of form 'a b 2 5' 
a b 2 5 
>>> vars = [int(i) if i.isdigit() else i for i in inp.split()] 
>>> vars 
['a', 'b', 2, 5] 

基本上,可以在相同的輸入具有多個空間分隔值,並且可以在以後將它們分割。

+0

非常感謝:) – rajathans 2015-02-11 10:41:56

+0

@rajathans如果有幫助,不要忘記[接受答案](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-工作):) – 2015-02-11 10:43:23

相關問題