Python len – How to use Python string length method

The string length in Python

The Python len() method returns the total number of characters in a given string. The Python string length method is quite useful especially if your program allows the limited number of characters for a text field or some other case.

An example of string length method

Syntax of Python length method

Following is the basic syntax of len() method:

len(string_name)

A string length example

The example below shows how len() method of Python is used to return the total number of characters in the given string. For that, we have created a string variable and assigned it a value at the time of declaration.

After that, we used the print function to display the output. In the print function, we used the len method to return the total characters in that string variable.

See this example online


Output will be:

The length of string is: 28

 

Also see: Python String

Was this article helpful?

Related Articles

Leave A Comment?