Reputation: 1
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
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
Reputation: 410662
If a function doesn't return anything, then it automatically returns None
.
Upvotes: 1