Find length of list using while loop without len() in python

 

#Python 3.7.5

L=[10,10,2]

i=0

while L[i:]:

   i+=1

print("Length is ",i)



#Likewise length of string 

S="NAME"

i=0

while S[i:]:

    i+=1

print("len is ",i)

Comments

Popular posts from this blog

Solving maze puzzle in python