# len() function with example in Python

Python len() function: Here, we are going to learn about the len() function in Python with example.
Submitted by IncludeHelp, on April 02, 2019

## Python len() function

len() function is a library function in Python, it is used to get the length of an object (object may a string, list, tuple, etc). It accepts an object and returns its length (total number of characters in case of a string, the total number of elements in case of an iterable).

Syntax:

```    len(object)
```

Parameter:object – an object like string, list etc whose length to be calculated.

Return value: int – returns length of the object.

Example:

```    Input:
a = "Hello world!"
print(len(a))

Output:
12
```

Python code to get the length of an object (string, list etc)

```# python code to demonstrate an example
# of len() function

a = "Hello world!"          # string value
b = [10, 20, 30, 40, 50]    # list
c = ["Hello", "World!", "Hi", "Friends"] # list of strings
d = ("Hello", "World!", "Hi", "Friends") # Tuple

print("length of a: ", len(a))
print("length of b: ", len(b))
print("length of d: ", len(c))
print("length of c: ", len(d))
```

Output

```length of a:  12
length of b:  5
length of d:  4
length of c:  4
```

Preparation
{"ft_lang_label":"__label__en","ft_lang_prob":0.71515304,"math_prob":0.9133056,"size":1223,"snap":"2022-05-2022-21","text_gpt3_token_len":335,"char_repetition_ratio":0.17227235,"word_repetition_ratio":0.028169014,"special_character_ratio":0.30662307,"punctuation_ratio":0.18532819,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9956867,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-05-26T01:31:42Z\",\"WARC-Record-ID\":\"<urn:uuid:1f6a57ff-b986-48d6-bb36-a9ee87cad388>\",\"Content-Length\":\"165678\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:4dd7c4ef-b388-49f6-ae0e-75868b73a387>\",\"WARC-Concurrent-To\":\"<urn:uuid:9da204f8-67f6-4572-8d60-c0b7bcd7781f>\",\"WARC-IP-Address\":\"172.67.208.70\",\"WARC-Target-URI\":\"https://www.includehelp.com/python/len-function-with-example.aspx\",\"WARC-Payload-Digest\":\"sha1:ZCTI66CCLPJLFIFQRCOFB4IMFXISB5CL\",\"WARC-Block-Digest\":\"sha1:NDWJSSHYP5LYDZM2LDJIQLGLMXFUJNVK\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-21/CC-MAIN-2022-21_segments_1652662595559.80_warc_CC-MAIN-20220526004200-20220526034200-00065.warc.gz\"}"}