String length with a loop

EasyString Programs · 9 of 106

Write a Python program to calculate the length of a string with a loop instead of len().

Advertisement
Input
"sqatools"
Output
8 True

Approach

  1. Count the characters one by one.

Solution

Python
text = "sqatools"count = 0for _ in text:    count += 1print(count, count == len(text))
Output
8 True

Learn the concept

New to this topic? Read the lesson, then come back.

More string programs

← All 106 String Programs

Leave a Comment