我這一小段代碼爲我的某種操作系統的字符串:「 n」個不工作
print("Type your document below.")
print("Press enter to save.")
print("Type \\n for a new line.")
file=input()
print("Enter a file name...")
filename=input()
outFile = open(filename, "w+")
outFile.write(file)
outFile.close()
但是當我運行該代碼(這在DEF),說我輸入的東西像這樣:
foo \n bar
因爲從用戶接收輸入時進入不工作,所以你必須使用\ n。
文件證明爲:
foo \n bar
代替:
foo
bar
在一個字符串中防止實際製作一個新行,而不是'爲新行輸入(新行)'它是'Type \ n for new line'。 – Xtreme