Python3.1版本中 print()如何回车后不打印数据?

Python3.3.1\u4e2dprint\u600e\u4e48\u4f7f\u4e0d\u6362\u884c\uff0c\u9017\u53f7\u8bd5\u8fc7\u4e86\u6ca1\u7528 python\u81ea\u52a8\u5316\u6d4b\u8bd5\u5e94\u8be5\u600e\u4e48\u5165\u624b\uff0c\u521a\u5b66\u51e0\u5929\u6c42\u7f69

\u56e0\u4e3aw[0:]\u8fd4\u56de\u503c\u662f\u4e2aw\u7684sub-list\uff0c\u91cc\u9762\u7684\u503c\u662fw[0],w[1],w[2].......
\u4f60\u8981\u663e\u793a\u5728\u4e00\u884c\u91cc\uff0c\u53ef\u4ee5\u8fd9\u6837\uff1a
for i in w[0:]: print i,3.0\u7684print\u6700\u540e\u52a0\u4e2a\u53c2\u6570end=""\u5c31\u53ef\u4ee5\u4e86
print("I am ", end="")print("fine")
:

\u6211\u60f3\u6211\u5927\u6982\u660e\u767d\u697c\u4e3b\u7684\u610f\u601d\uff0c\u697c\u4e3b\u5e94\u8be5\u662f\u5728python\u7684shell\u91cc\u9762\u5199\u4ee3\u7801.
\u7f16\u5199\u4e86print('1')\u540e\u56de\u8f66shell\u5c31\u4f1a\u8f93\u51fa1\uff0c\u7136\u540e\u5f00\u59cb\u65b0\u884c\uff0cpython\u7684shell\u5c31\u662f\u8fd9\u4e48\u8bbe\u8ba1\u7684\u3002

\u5982\u679c\u60f3\u8f93\u5165\u591a\u884c\u8bed\u53e5\u4e00\u6b21\u8fd0\u884c\u7684\u8bdd\uff0c\u53ef\u4ee5\u5148\u5b9a\u4e49\u4e00\u4e2a\u65b9\u6cd5\uff0c\u7136\u540e\u8c03\u7528\uff0c\u6bd4\u5982(\u7531\u4e8e\u6211\u7684python\u7248\u672c\u975e3.1,\u6240\u4ee5print\u8bed\u53e5\u683c\u5f0f\u4f1a\u4e0d\u4e00\u6837):

>>> def myprint():
... print '1'
... print '2'
...
>>> myprint()
1
2

\u6216\u8005\u5efa\u7acbpy\u6587\u4ef6\uff0c\u8fd9\u662f\u6211\u6bd4\u8f83\u63a8\u8350\u7684\u65b9\u6cd5\uff1a

\u5efa\u7acb\u4e00\u4e2aa.py\u6587\u4ef6
=========================
#coding: -*- utf-8 -*-

print('1')
print('2')
...
...something else..

\u7136\u540e\u5728\u547d\u4ee4\u884c\u8f93\u5165python a.py\u5c31\u53ef\u67e5\u770b\u7ed3\u679c

我想我大概明白楼主的意思,楼主应该是在python的shell里面写代码.
编写了print('1')后回车shell就会输出1,然后开始新行,python的shell就是这么设计的。

如果想输入多行语句一次运行的话,可以先定义一个方法,然后调用,比如(由于我的python版本非3.1,所以print语句格式会不一样):

>>> def myprint():
... print '1'
... print '2'
...
>>> myprint()
1
2

或者建立py文件,这是我比较推荐的方法:

建立一个a.py文件
=========================
#coding: -*- utf-8 -*-

print('1')
print('2')
...
...something else..

然后在命令行输入python a.py就可查看结果

print本来就是用来输出的,你不让他输出为什么还写呢?

扩展阅读:python手机版下载安装 ... python3.7下载免费版 ... python3.6下载官网 ... python3.4下载安装 ... python3ide手机版下载app ... pycharm不支持python3.1 ... python网站 ... python天天向上续3.3 ... python3.1鸡兔同笼编程 ...

本站交流只代表网友个人观点,与本站立场无关
欢迎反馈与建议,请联系电邮
2024© 车视网