Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python输入解释器_Python_Python 3.x - Fatal编程技术网

Python输入解释器

Python输入解释器,python,python-3.x,Python,Python 3.x,如果我键入PRINT“HELLO WORLD”,如何让我的微型口译员说HELLO WORLD试试以下方法: test = input( '> ').strip() if test == 'PRINT' : print( test ) else : print('FAILURE') 运行此命令并输入PRINT'HELLO WORLD'将导致shell打印出'HELLO WORLD'我想您需要字符串的拆分方法。你给它一个分裂的特征;您将返回一个已分割字符串的列表。比如说, t

如果我键入PRINT“HELLO WORLD”,如何让我的微型口译员说HELLO WORLD试试以下方法:

test = input( '> ').strip()
if test == 'PRINT' :
    print( test )
else :
    print('FAILURE')

运行此命令并输入
PRINT'HELLO WORLD'
将导致shell打印出
'HELLO WORLD'

我想您需要字符串的拆分方法。你给它一个分裂的特征;您将返回一个已分割字符串的列表。比如说,

test = input('> ')
command, _, args = test.partition(' ') if test else (None, None, None)
if command == 'PRINT':
    print(args[1:-1])
else:
    print('FAILURE')
给你名单

divide = test.split("'")  # Single quotation mark is the divider

您能从那里完成吗?

您应该使用raw\u input()raw\u input?只有输入对我有效,有没有办法只输出'@UserBOBBED'之间的文本?你必须使用Python 3,只需将
raw\u input
替换为
input
。是的,这是可能的,请参阅编辑后的答案(只需切掉第一个和最后一个字符)。谢谢,这太棒了
["PRINT ", "HELLO WORLD"]