简体   繁体   English

在Visual Studio中编写语句时无代码输出

[英]No code output when writing statements in Visual Studio

I'm new to Python. 我是Python的新手。 I have visual studio and the Python 2.7 shell. 我有Visual Studio和Python 2.7 Shell。

I can run 5 + 5 in the Python shell which outputs 10. 我可以在输出10的Python shell中运行5 + 5。

However if I do 5 + 5 in visual studio, I don't get an output. 但是,如果我在Visual Studio中执行5 + 5,则不会得到输出。 Why is this the case? 为什么会这样呢?

That is because, when you use the python shell. 那是因为,当您使用python shell时。 Shell is executing 5 + 5 when you press enter. 当您按Enter键时,Shell将执行5 + 5。 Meaning shell executes you commands line by line, as you type them. 意味着shell在您键入命令时逐行执行命令。

On the other hand Visual Studio is not a shell environment, it is an IDE (editor). 另一方面,Visual Studio不是外壳环境,而是IDE(编辑器)。 Which allows you to write the whole python program and then execute it all at once. 这样您就可以编写整个python程序,然后立即执行所有程序。

In the shell the "addition" is evaluated immediately. 在外壳中,将立即评估“加法”。

In the editor you have to write: 在编辑器中,您必须编写:

print(5 + 5)

You have to tell the program, that it should "print" something in the shell. 您必须告诉程序,它应该在外壳中“打印”某些东西。

More Examples: 更多示例:

print("this will be printed")

print("this is a" + "test")

In the last example the second string is appended to the first one. 在最后一个示例中,第二个字符串附加到第一个字符串。

For reference or learning Python 供参考或学习Python

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM