我只是在shell提示符下输入了以下内容,效果很好:
$ python
Python 2.7.3 (default, Aug 1 2012, 05:16:07)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> my_age = 35
>>> my_eyes = 'Blue'
>>> print "my age is %d and my eye color is %s" % (my_age, my_eyes)
my age is 35 and my eye color is Blue
>>>
在交互式Python解释器中键入多行代码的方法是在交互式Python解释器中键入多行代码。我认为这足以满足您的目的。
的确,每行之后都会出现一个新的提示,这意味着如果您的两行代码产生输出,则该输出将由提示分隔。我想这就是您所关心的,尽管您的问题中的示例并没有建议:
$ python
Python 2.7.3 (default, Aug 1 2012, 05:16:07)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print "first line"
first line
>>> print "second line"
second line
>>>
如果这是一个问题,则可以将多个语句括在(适当缩进!)if语句中:
$ python
Python 2.7.3 (default, Aug 1 2012, 05:16:07)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> if 1:
... print "first line"
... print "second line"
...
first line
second line
>>>
(我建议,即使它不能回答您的问题,如果您编写的代码足够复杂,那么您应该编写脚本。也许您已经在一年半的时间里开始这样做了。自从您发布了问题。)