Home  >  Article  >  Backend Development  >  为什么python代码有时候在命令行下和Python Shell中执行的结果不一样呢 ?

为什么python代码有时候在命令行下和Python Shell中执行的结果不一样呢 ?

WBOY
WBOYOriginal
2016-06-06 16:22:171677browse

回复内容:

首先,如上面 @柯豪 的答案所说,Shell的行为并不完全和Python代码一致

>>> for i in range(5):
...     i
... 
0
1
2
3
4
这个例子非常有意思,无人邀请,我来答一下吧。

使用不熟悉的函数和library是危险的。
使用不熟悉的函数和library是危险的。
使用不熟悉的函数和library是危险的。
重要的话说三遍。

首先,先看这个例子,只是把helloworld.cpp 略加改动,题主觉得这个代码应当输出什么结果?
#include 
#include 

using namespace std;

int main()
{
    coutprintf("asdf")endl;
}
为什么python代码有时候在命令行下和Python Shell中执行的结果不一样呢 ?主要是因为这东西变了.
而c库中的标准的输出没改变.
具体可以看这个文章 eli.thegreenplace.net/2
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn