Python program to Find the Longest Word in a String

str = input("Insert some strings: ")
totalstr = str.split()
longest = 0
for i in range(1, len(totalstr)):
 if len(totalstr[longest]) < len(totalstr[i]):
  longest = i
print(totalstr[longest])

 

 

Output:

Insert some strings: my, java, tutorial, with python, cpp tutorials, learn web development
development

 

Insert some strings: python tutorials for beginners. Learn Python with beginner programming examples
programming

 

Subscribe For Daily Updates