Python Strings

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

[pastacode lang=”bash” manual=”‘Wikitechy’%C2%A0is%20the%20same%20as%C2%A0%22Wikitechy%22.” message=”” highlight=”” provider=”manual”/]

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

[pastacode lang=”python” manual=”len(string)” message=”” highlight=”” provider=”manual”/]

Parameters:

It takes string as the parameter

Return Value:

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

[pastacode lang=”python” manual=”%0A%23%20Python%20program%20to%20demonstrate%20the%20use%20of%20%0A%23%20len()%20method%20%20%20%0A%20%20%0A%23%20Length%20of%20below%20string%20is%205%20%0Astring%20%3D%20%22wikitechy%22%20%0Aprint(len(string))%20%0A%20%20%0A%23%20Length%20of%20below%20string%20is%2015%20%0Astring%20%3D%20%22Wikitechy%20wikitechy%22%20%0Aprint(len(string))%20%0A%0A” message=”” highlight=”” provider=”manual”/]

Output:

[pastacode lang=”python” manual=”9%0A19%0A” message=”” highlight=”” provider=”manual”/]

Categorized in: