Press "Enter" to skip to content

Python Program to Calculate the Length of a String Without Using an inbuilt Function

In this post, we will see how to Calculate the Length of a String Without Using an inbuilt Function.
Algorithm
Step 1: Declare a String and store it in a variable.
Step 2: Declare a variable stringLength and initialize it to 0.
Step 3: Use a for loop to iterate over the string and increment the stringLength variable for each character in the string.
Step 4: After completing the for loop print the value of stringLength variable.
Step 5: End.
Example

Input: "Welcome to Python Programming";
Output: Length of the string is: 29

Program

string="Welcome to Python Programming";
stringLength=0
for i in string:
      stringLength=stringLength+1
print("Length of the string is: ")
print(stringLength)

Output

Length of the string is:29

Comments are closed.