From list of strings, length of longest string

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
  1. Take a list of strings as input.
  2. Create a variable named temp and assign its value equal to zero.
  3. Use for loop to iterate over each string of the list.
  4. 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.
  5. 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
				
			

string made of the first and the last 2 characters

string made of 4 copies of the last two characters

Leave a Comment