{"id":24829,"date":"2021-11-02T09:54:23","date_gmt":"2021-11-02T04:24:23","guid":{"rendered":"https:\/\/python-programs.com\/?p=24829"},"modified":"2021-11-05T20:37:44","modified_gmt":"2021-11-05T15:07:44","slug":"python-len-function-with-examples","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-len-function-with-examples\/","title":{"rendered":"Python len() Function with Examples"},"content":{"rendered":"

In the previous article, we have discussed Python locals() Function with Examples<\/a>
\nlen() Function in Python:<\/strong><\/p>\n

The number of items in an object is returned by the len() function.<\/p>\n

The len() function returns the number of characters in a string when the object is a string.<\/p>\n

Syntax:<\/strong><\/p>\n

len(object)<\/pre>\n

Parameters<\/strong><\/p>\n

object:<\/strong> This is Required. It is an object. It should be a sequence or a collection.<\/p>\n

Return Value:<\/strong><\/p>\n

The number of items in an object is returned by the len() function.<\/p>\n

A TypeError exception will be thrown if an argument is not passed or if an invalid argument is passed.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given List = [1, 20, 3, 40, 5]<\/pre>\n

Output:<\/strong><\/p>\n

The length of the given list =  5<\/pre>\n

Example2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given String = \"hello btechgeeks\"<\/pre>\n

Output:<\/strong><\/p>\n

The length of the given string =  16<\/pre>\n

len() Function with Examples in Python<\/h2>\n