我對這個問題的處理很困難。每次我嘗試在這個程序中反斜槓,它只會給我一個錯誤。「行」之前的反斜槓字符 - Python3中的打印功能
我想該行
print(day,\\month,\\year"is a magic date")
但無論我怎麼經常嘗試別的東西,似乎沒有任何工作。任何建議都會非常有幫助。
我對這個問題的處理很困難。每次我嘗試在這個程序中反斜槓,它只會給我一個錯誤。「行」之前的反斜槓字符 - Python3中的打印功能
我想該行
print(day,\\month,\\year"is a magic date")
但無論我怎麼經常嘗試別的東西,似乎沒有任何工作。任何建議都會非常有幫助。
你需要告訴Python中 「\」 是一個字符串:
>>> print(day, "\\", month, "\\", year, "\\", "is a magic date")
1 \ Sep \ 1978 \ is a magic date
你也可以指定sperator:
>>> print(day, "\\", month, "\\", year, "\\", " is a magic date", sep=" ")
1 \ Sep \ 1978 \ is a magic date
或者乾脆:
>>> print(day ,month, year, " is a magic date", sep="\\")
1\Sep\1978\ is a magic date
哦。非常感謝你。我甚至沒有想到這一點。我曾嘗試過其他任何組合。 – Nick
你會期望那些反斜槓做什麼? – stranac
用以下格式分隔一天中的月份和年份6/10/60 – Nick
如果您想打印正斜槓,我無法想象爲什麼在您的問題中放置反斜槓......但好的,這解釋了您想要執行的操作。 – stranac