programming-examples/python/Misc/Python program to find the length of the last word.py
2019-11-15 12:59:38 +01:00

10 lines
310 B
Python

def length_of_last_word(s):
words = s.split()
if len(words) == 0:
return 0
return len(words[-1])
print(length_of_last_word("Python Exercises"))
print(length_of_last_word("Python"))
print(length_of_last_word(""))
print(length_of_last_word(" "))