![](/img/trans.png)
[英]Python:How do I print not only the final value after running the for statement, but also the middle output?
[英]How do I change the output format of a print statement in python?
我寫了下面的代碼
A = print("apple")
並且,我想將A的數據類型更改為字符串,因此我編寫了以下代碼。
A = str(print"apple")
type(A)
但是,答案是“無”。 在這種情況下我該怎么辦?
實際上,我現在正在做的是將類似輸出的內容寫入文本文件。
openFp = open("solution.txt","w")
p2 = str(print("I_B : ",I_B))
openFp.writelines(p2+"\n")
openFp.close()
輸入此代碼將始終顯示“無”。
這不可能。
因為print
只是簡單地打印參數,然后什么都不返回,所以您強制打印print(...)
或將其設為變量,因此它將為None,因此您無能為力。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.