Python string length | len()

Python Strings

Strings in python are enclosed by either single quotation marks, or double quotation marks.

'Wikitechy' is the same as "Wikitechy".

Python string length | len()

  • len() function is an inbuilt function in Python programming language that returns the length of the string, array, list, tuple, dictionary, etc.
  • You can use len function to optimize the performance of the program. The number of elements stored in the object is never calculated, so len helps provide the number of elements.

Syntax

len(string)

Parameters:

It takes string as the parameter

Return Value:

It returns an integer which is the length of the string.


# Python program to demonstrate the use of
# len() method

# Length of below string is 5
string = "wikitechy"
print(len(string))

# Length of below string is 15
string = "Wikitechy wikitechy"
print(len(string))

Output:

9
19

Praveen Kumar

I am a fullstack web developer with a passion for SEO, creating stunning websites, and organic marketing. I am a perfectionist.

Post navigation