Search This Blog

Thursday, 18 November 2021

python program to pass a string to the Function. Return and display the longest word

 Write a python program to pass a string to the function .Return and display the longest word

def longest_word(n):
n1=""
for i in n.split():
if len(i)>len(n1):
n1=i
print("longest word ",n1)
def main():
#n=input("Enter any string ")
n="Hello how are you greeting you"
print("String is ",n)
longest_word(n)
"""
if __name__=='__main__':
main()
"""
#or
#function calling
main()

Output:-
(1). String is Hello how are you greeting you
longest word greeting
(2).If n=”Nice to meet you” then,

String is Nice to meet you
longest word Nice

No comments:

Post a Comment

how to implement YOLOv3 using Python and TensorFlow

Object Detection with YOLOv3 Introduction YOLOv3 (You Only Look Once version 3) is a real-time object detection algorithm that can detect ob...