n=str(input("Enter your name"))
a=str(input("Where do you live?"))
print("Hello",n,"How is the weather at",a,"?")
如何洗掉列印陳述句中 {a & ?} 之間的空格?
uj5u.com熱心網友回復:
f-string可以讓您更好地控制確切的格式:
print(f"Hello {n}. How is the weather at {a}?")
uj5u.com熱心網友回復:
Commas在 python 中,在輸出中添加一個空格。不需要str在 python 中用作輸入已經被視為字串。你可以使用這個:
n = input("Enter your name")
a = input("Where do you live?")
print("Hello",n,"How is the weather at",a "?")
這將連接兩個字串。
要么
n = input("Enter your name")
a = input("Where do you live?")
print(f"Hello {n}! How is the weather at {a}?")
這被稱為f-strings。它格式化字串,以便您可以將變數的值放入輸出中。
uj5u.com熱心網友回復:
你可以簡單地通過end在里面使用print
默認情況下,它的值是\n,如果您將其設定為空字串''
,則不會添加任何內容(或任何空格)。列印后a,?將在此之后列印。
所以你可以寫下面的代碼:
print("Hello",n,"How is the weather at",a, end='')
print("?")
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/441705.html
上一篇:計算用戶輸入的坐標值的中點。(x,y,z軸)需要課堂主題
下一篇:使用字典映射多個列和值
