Can anyone tell me how can I get the length of a string without using the len()
function or any string methods. Please anyone tell me as I\'m tapping my head ma
easy:
length=0
for x in "This is a string":
length+=1
print(length)
String length without using len function in python-
def strlen(myStr):
if(myStr==""):
return 0
else:
return 1+strlen(myStr[1:])
Create a for loop
styx = "How do I count this without using Lens function" number = 0 for c in styx: number = 0 + 1 print(number)
Not very efficient but very concise:
def string_length(s):
if s == '': return 0
return 1 + string_length(s[1:])
def length(object):#Define the length calculation function
count = 0 #initializing the length to be equal to zero
object = input() #enter the argument
for i in object:
count=count+1
print("Length of the string is"+str(count))
length(object)