簡體   English   中英

VSCode Python - 打印語句不打印輸出

[英]VSCode Python - print statement not printing to output

我是 VSCode 的新手。 我已經在 Windows 上設置了它。 當我使用 Code Runner 運行它時,我看到正在運行和完成消息,但打印語句不起作用。

print("Hello World!")
print ("This is VS Code")
a=1
while a <10:
    print a
    a = a+ 1

這是輸出:

[Running] python -u "c:\Users\user\PythonWorkArea\VSCode\HelloWorld\app.py"
[![\[Done\] exited with code=0 in 0.293 seconds][1]][1]

打印語句不起作用。

在此處輸入圖像描述

我究竟做錯了什么?

您應該選擇您正在使用的適當的 Python 環境,執行 Control+Shift+P -> Python: Select Interpreter。

我遇到了同樣的問題,必須更改默認環境才能使其正常工作。

試試這個:

print("Hello world!")
print("This is VS Code")
a = 0
while a < 10:
    print(a)
    a += 1

“a”尚未定義。 我很驚訝您沒有收到“未定義錯誤”消息。 這應該工作...

a = 0

while(a < 10):
  print(a)
  a +=1

實現此目的的最簡單方法是安裝Coderunner擴展。 它會自動在你的 VS 代碼終端中顯示你的打印語句。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM