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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

請(qǐng)老師解答

# Enter a code

template='Life is short,you need {P}'

ch='python'

result=template.format(P=ch)

print(result)


#這里,為什么不能直接給P賦值呢?

# Enter a code

template='Life is short,you need {P}'

P='python'

result=template.format(P)

print(result)

#這個(gè)程序?yàn)槭裁磿?huì)出錯(cuò)呢?

正在回答

2 回答

template='Life?is?short,you?need?{P}'

P='python'

result=template.format(P=P)

print(result)

P相當(dāng)于占位符,沒有給他賦值

1 回復(fù) 有任何疑惑可以回復(fù)我~

template='Life is short,you need {P}'這里的P和

P='python'這里的P并不是同一個(gè)P

第一個(gè)P是給模板里的參數(shù)指定一個(gè)名字,方便調(diào)用

第二個(gè)P是變量名

result=template.format(P)這里的P是變量名

改成如下就正確(不指定參數(shù)名字):

template='Life is short,you need {}'

P='python'

result=template.format(P)

print(result)

或者改成如下(指定參數(shù)名字)

template='Life is short,you need {P}'

P='python'

result=template.format(P=P)

print(result)


這里面的result=template.format(P=P)第一個(gè)P是指參數(shù)名字,第二個(gè)P是變量名

為了避免混淆,一般要區(qū)分開來,如下:

template='Life is short,you need {x}'

P='python'

result=template.format(x=P)

print(result)


1 回復(fù) 有任何疑惑可以回復(fù)我~
#1

嘿呀2021

這個(gè)寫的很清楚
2022-11-08 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

請(qǐng)老師解答

我要回答 關(guān)注問題
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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