Monday, March 16, 2026

String Length in Python - len() Function

The len() function in Python is the simplest and most efficient way to determine the length of a string, list, tuple, dictionary, or any other iterable. When applied to a string, the len() function returns the total number of characters, including spaces and special symbols.

Syntax of len() function

len(object)

object can be a string, list, tuple, dictionary, or any iterable.

The function returns an integer representing the number of items or characters (in case of string) contained in the object.

String length using len() in Python

str = "netjs"
print(len(str))

str = "Hello World!"
strLen = len(str)
print('length of String- ',strLen)

Output

5
length of String-  12

That's all for this topic String Length in Python - len() Function. If you have any doubt or any suggestions to make please drop a comment. Thanks!

>>>Return to Python Tutorial Page


Related Topics

  1. String Slicing in Python
  2. Python String split() Method
  3. Python Program to Check if Strings Anagram or Not
  4. Class And Object in Python
  5. Inheritance in Python

You may also like-

  1. Magic Methods in Python With Examples
  2. Namespace And Variable Scope in Python
  3. List in Python With Examples
  4. Tuple in Python With Examples
  5. Access Modifiers in Java
  6. How to Convert Date And Time Between Different Time-Zones in Java
  7. Spring Component Scan Example
  8. Installing Hadoop on a Single Node Cluster in Pseudo-Distributed Mode