簡體   English   中英

將變量和換行符放入Python的打印語句中

[英]Putting variables and line breaks into print statements in Python

我在此代碼中不斷收到語法錯誤。 有人可以在這里看到任何格式錯誤嗎?

for i in range (10,-1,-1):
    b="green bottles sitting on the wall"
    print(i,b,\n,i,b,\n,"And if one green bottle should accidentally fall"\n"There will be",i,b)

這是更正的一個:

for i in range (10,-1,-1):
    b = "green bottles sitting on the wall"
    print(i, b, '\n', i, b, '\nAnd if one green bottle should accidentally fall\nThere will be', i, b)

應該是這樣的:

print(i,b,"\n",i,b,"\n","And if one green bottle should accidentally fall\nThere willbe",i,b)

\\n應該是一個字符串。 反斜杠(\\)字符用於轉義具有特殊含義的字符。

暫無
暫無

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

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