打印不出來
# -*- coding: utf-8 -*
def greet(s):
? ? if s is None:
? ? ? ?print ('hello word')
? ? else:
? ? ? ? print 'hello'+s
greet()
greet('Bart')
# -*- coding: utf-8 -*
def greet(s):
? ? if s is None:
? ? ? ?print ('hello word')
? ? else:
? ? ? ? print 'hello'+s
greet()
greet('Bart')
2018-12-26
舉報
2018-12-29
對于這種情況,可以把s作為默認參數,賦初值為0,這樣的話如果有輸入,s就會為字符型,沒有輸入,s就是0為整型,就區分開來了,同時也解決了沒有輸入值報錯的問題
2018-12-29
greet()只接受一個參數,默認0,不能為空
2018-12-26
先判斷是不是空的要是空的 就打印hello word? 不是就打印 hello xxx 感覺思路沒有問題 會報錯 也看不懂 大神們給個解決方案?TypeError: greet() takes exactly 1 argument (0 given)