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
0 Shares:
You May Also Like
Read More

Data Types in Python

Definition Data types in Python are classifications that specify the type of value a variable holds, determining what…
Read More

Robot Framework in Python

Definition Robot Framework is an open-source, keyword-driven test automation framework that uses Python for writing and executing automated…