Quantcast
Channel: JS Tricks » Python
Viewing all articles
Browse latest Browse all 25

Python String len Method – Python len()

$
0
0

In this lesson we will learn about Python String len method. This len method will return the number of elements in the String.

Python String len Method

Python String len method is an effective way to get the number of elements in a String. The len method can also be used for getting number of elements in Dictionary and Tuple.

Syntax

The syntax for len method is given below:

len( myString )

  •  myString – that specific String of which you want to get the number of elements.

This method will return the number of elements.

Examples

Here are some examples of Python String len method:

myString1 = 'Hello World'
myString2 = 'My name is John Doe'
 
print " Length of myString1 is : ", len( myString1 )
print " Length of myString2 is : ", len( myString2 )

If you run this script then the output will look like this:

Length of myString1 is : 11
Length of myString2 is : 19

 

The post Python String len Method – Python len() appeared first on JS Tricks.


Viewing all articles
Browse latest Browse all 25

Trending Articles