Bartek Biskupski
Bartek Biskupski

Reputation: 1

Function giving unexpected result

Could anyone explain why this function gives "None" at the end?

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

Upvotes: 0

Views: 61

Answers (2)

Michael Schultz
Michael Schultz

Reputation: 29

The function is returning None because there is no other explicit return value; If a function has no return statement, the default is None.

Upvotes: 2

mipadi
mipadi

Reputation: 410662

If a function doesn't return anything, then it automatically returns None.

Upvotes: 1

Related Questions