課程
/后端開發(fā)
/Python
/初識Python
def greet(x,y='Hello,'): ? ?while x == ture: ? ? ? ?x = 'xxx.' ? ?x = 'world.' ? ?print 'y'+'x' 幫我看看我這樣為什么不行?
2016-07-26
源自:初識Python 7-6
正在回答
不是這樣寫的,默認(rèn)參數(shù)是world 不是hello,應(yīng)該這樣寫
def greet(name='world'):
print 'Hello'+','+name+'.'??? #這樣沒有傳入的時(shí)候打印的是'hello,+name'name就是默認(rèn)的參數(shù),打印出來就是hello,world.
greet()
greet('Bart')? #這是調(diào)用那個(gè)函數(shù)傳入了一個(gè)參數(shù),來替代默認(rèn)參數(shù),所以此時(shí)print的結(jié)果是 hello,Bart.
希望能幫到你 我也剛學(xué)兩天
慕容6137442 提問者
舉報(bào)
學(xué)python入門視頻教程,讓你快速入門并能編寫簡單的Python程序
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網(wǎng)安備11010802030151號
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號
2016-07-26
不是這樣寫的,默認(rèn)參數(shù)是world 不是hello,應(yīng)該這樣寫
def greet(name='world'):
print 'Hello'+','+name+'.'??? #這樣沒有傳入的時(shí)候打印的是'hello,+name'name就是默認(rèn)的參數(shù),打印出來就是hello,world.
greet()
greet('Bart')? #這是調(diào)用那個(gè)函數(shù)傳入了一個(gè)參數(shù),來替代默認(rèn)參數(shù),所以此時(shí)print的結(jié)果是 hello,Bart.
希望能幫到你 我也剛學(xué)兩天