Find the Length of a String Without Using len Function in Python Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report In this article, we will explore different methods to find the length of a string without using the len() function in Python. We will look at several techniques like loops, recursion, and generator expressions. These approaches help us manually calculate the length of a string.Using sum()sum() with generator expression quickly counts the characters in a string without needing a loop or extra variables. It’s a simple and efficient approach. Python s = "GeeksforGeeks" l= sum(1 for i in s) print(l) Output13 Explanation:sum(): Sums up the values generated by the expression.(1 for i in s):This generates 1 for each character in s.Table of ContentUsing enumerate()Using for loop Using RecursionUsing iter() Using enumerate()We use enumerate() to go through a list or string while keeping track of the position (index) and the item itself. It makes it easier to work with both the item and its position at the same time. Python s = "GeeksforGeeks" n = 0 for i, char in enumerate(s): # Unpacking the tuple (index, character) n = i + 1 print(n) Output13 Using for loop for loop counts characters in a string by going through each one, but requires manual updates, making it a bit less efficient than other methods. Python s = "GeeksforGeeks" l = 0 for char in s: l += 1 print(l) Output13 Using RecursionRecursion counts characters by repeatedly calling the function until the string is empty. It’s simple but less efficient because of extra function calls. Python def fun(s): if s == "": # Base case return 0 else: # add 1 and call fun on the rest of the string return 1 + fun(s[1:]) s = "Hello World" res = fun(s) print(res) Output11 Using iter() iter() and next()creates an iterator to go through the string and count its characters. It works but is less efficient because it requires handling extra steps and exceptions. Python s = "GeeksforGeeks" # Create an iterator i = iter(s) # Initialize count l = 0 try: while True: # Move to next character next(i) # Increment count l += 1 # Stop when iteration finishes except StopIteration: pass print(l) Output13 Create Quiz Comment A am8254s3a Follow 0 Improve A am8254s3a Follow 0 Improve Article Tags : Python Python Programs python-string python-basics Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 4 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 3 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 3 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 4 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 3 min read StatsModel Library - Tutorial 3 min read Learning Model Building in Scikit-learn 6 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 5 min read Build a REST API using Flask - Python 3 min read Building a Simple API with Django REST Framework 3 min read Python PracticePython Quiz 1 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like