Small Python Program For Beginners To Practice |
In this article, we are going to write a Python Code to Print out the maximum string of length inside a string. For this, first, we break the string sentence at the space and then proceed with the code.
If you are looking for a Python Tutorial series then it's here
example = "Hello My name is Ninza and I am a developer"
x = example.split(' ')
print(x)
print(len(x))
max_len = -1
for element in x:
if len(element) > max_len:
max_len = len(element)
response = element
print(response)
The output of the code is:
['Hello', 'My', 'name', 'is', 'Ninza', 'and', 'I', 'am', 'a', 'developer']
10
developer
Comments
Post a Comment