第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

不確定如何從字符串中刪除空格

不確定如何從字符串中刪除空格

忽然笑 2023-06-20 10:37:00
current_price = int(input())last_months_price = int(input())print("This house is $" + str(current_price), '.', "The change is $" +      str(current_price - last_months_price) + " since last month.")print("The estimated monthly mortgage is ${:.2f}".format((current_price * 0.051) / 12), '.')這會產(chǎn)生:This house is $200000 . The change is $-10000 since last month.The estimated monthly mortgage is $850.00 ."$200000"我不確定如何刪除and之后的空白"$850.00"。我不完全理解這個strip()命令,但從我讀到的內(nèi)容來看,它對這個問題沒有幫助。
查看完整描述

3 回答

?
ABOUTYOU

TA貢獻(xiàn)1812條經(jīng)驗 獲得超5個贊

你可以給 print 一個額外的參數(shù):sep,像這樣:

print("This house is $" + str(current_price), '.', "The change is $" + 
     str(current_price - last_months_price) + " since last month.", sep='')

因為默認(rèn)是逗號后的空格。


查看完整回答
反對 回復(fù) 2023-06-20
?
手掌心

TA貢獻(xiàn)1942條經(jīng)驗 獲得超3個贊

也許嘗試 f-string 注入

print(f"This?house?is?${current_price}.?The?change?is?${current_price?-?last_months_price}?since?last?month.")

f-string(格式化字符串)提供了一種使用最少語法將表達(dá)式嵌入字符串文字的方法。這是一種連接字符串的簡化方法,無需顯式調(diào)用str除字符串以外的格式化數(shù)據(jù)類型。

您也可以傳遞sep=''print,但這需要您將其他字符串與格式正確的空格連接起來。


查看完整回答
反對 回復(fù) 2023-06-20
?
斯蒂芬大帝

TA貢獻(xiàn)1827條經(jīng)驗 獲得超8個贊

print("This house is $" + str(current_price), '.',' ' "The change is $" +

      str(current_price - last_months_price) + " since last month.", sep='')

print("The estimated monthly mortgage is ${:.2f}"'.'.format((current_price * 0.051) / 12))



查看完整回答
反對 回復(fù) 2023-06-20
  • 3 回答
  • 0 關(guān)注
  • 147 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號