In this program, we will take a list of strings as input and returns the length of the longest string.
Steps to solve the program
- Take a list of strings as input.
- Create a variable named temp and assign its value equal to zero.
- Use for loop to iterate over each string of the list.
- Check if the length of the string is greater than the temp value, if yes assign the length of that string to the temp variable.
- Print the length of the longest string.
#input string
string = ["i", "am", "learning", "python"]
temp = 0
for word in string:
a = len(word)
if a > temp:
temp = a
#Printing output
print(temp)
Output :
8