2016-10-16 12 views
0

この関数が "None"を最後に与える理由を誰もが説明できますか?予期せぬ結果を与える関数

def displayHand(hand): 
    """ 
    Displays the letters currently in the hand. 

    For example: 
    >>> displayHand({'a':1, 'x':2, 'l':3, 'e':1}) 
    Should print out something like: 
     a x x l l l e 
    The order of the letters is unimportant. 

    hand: dictionary (string -> int) 
    """ 
    for letter in hand.keys(): 
     for j in range(hand[letter]): 
      print(letter,end=" ")  # print all on the same line 
    print()        # print an empty line 
+1

すべての関数の最後に暗黙の 'return None'があります。何も返さない場合、' None'を返します。 –

+0

どこにNoneがありますか?このコードでは関数を呼び出さない。 –

答えて

1

関数が何も返さない場合、自動的にNoneを返します。

2

他の明示的な戻り値がないため、この関数はNoneを返します。関数にreturn文がない場合、デフォルトはNoneです。

+0

printx(displayhand({'a':1、 'x':2、 'l':3、 'e':1})と呼ばれるときには何を返すのですか?これはaxxllleですが、二行目。 –

+0

Ok、nvm。私は愚かです...二度目に印刷しようとしました.... –

関連する問題