{"id":14111,"date":"2025-05-27T10:03:15","date_gmt":"2025-05-27T10:03:15","guid":{"rendered":"https:\/\/www.bodhost.com\/kb\/?p=14111"},"modified":"2026-02-26T14:02:08","modified_gmt":"2026-02-26T14:02:08","slug":"how-to-find-length-of-list-in-python","status":"publish","type":"post","link":"https:\/\/www.bodhost.com\/kb\/how-to-find-length-of-list-in-python\/","title":{"rendered":"How to Find the Length of a List in Python"},"content":{"rendered":"<p>In Python, a list is a way to store multiple items in a single variable. For example, you might have a list of numbers, names, or even a mix of different types of data. Sometimes, you need to know how many items are in a list. This is called the length of the list.<\/p>\n<p>Python makes it very easy to find the length using a built-in function called\u00a0<code>len()<\/code>. Let\u2019s go through this step by step.<\/p>\n<h4><strong>Step 1: What is a List?<\/strong><\/h4>\n<p>A list is a collection of items written inside square brackets\u00a0<code>[]<\/code>. Items are separated by commas.<\/p>\n<p>numbers = [5, 10, 15, 20]<\/p>\n<p>This list has 4 items: 5, 10, 15, and 20.<\/p>\n<h4><strong>Step 2: Why Do We Need the Length of a List?<\/strong><\/h4>\n<p>Knowing the length of a list is useful when:<\/p>\n<ul>\n<li>You want to loop through all items.<\/li>\n<li>You want to check if the list is empty.<\/li>\n<li>You want to divide the list into parts.<\/li>\n<li>You want to display the number of items to the user.<\/li>\n<\/ul>\n<h4><strong>Step 3: Using the\u00a0<code>len()<\/code>\u00a0Function<\/strong><\/h4>\n<p>Python provides a simple function called\u00a0<code>len()<\/code>\u00a0to count the number of items in a list.<\/p>\n<p><strong>Syntax:<\/strong><\/p>\n<div>len(list_name)<\/div>\n<div><\/div>\n<div><strong>Example:<\/strong><\/div>\n<div>numbers = [5, 10, 15, 20]<br \/>\nprint(len(numbers))<\/div>\n<div><\/div>\n<div><strong>Output:<\/strong><\/div>\n<div>4<\/div>\n<div>This means the list has 4 items.<\/div>\n<div><\/div>\n<div>\n<h4><strong>Step 4: Storing the Length in a Variable<\/strong><\/h4>\n<p>You can also store the result of\u00a0<code>len()<\/code>\u00a0in a variable if you want to use it later in your program.<\/p>\n<p><strong>Example:<br \/>\n<\/strong>fruits = [&#8220;apple&#8221;, &#8220;banana&#8221;, &#8220;cherry&#8221;]<br \/>\ncount = len(fruits)<br \/>\nprint(&#8220;There are&#8221;, count, &#8220;fruits in the list.&#8221;)<\/p>\n<p><strong>Output:<\/strong><br \/>\nThere are 3 fruits in the list.<strong><br \/>\n<\/strong><\/p>\n<h4><strong>Step 5:\u00a0<code>len()<\/code>\u00a0Works with Other Data Types Too<\/strong><\/h4>\n<p>The\u00a0<code>len()<\/code> Function is not just for lists. It also works with:<\/p>\n<ul>\n<li>Strings\u00a0\u2013 counts the number of characters<\/li>\n<li>Tuples \u2013 count the number of items<\/li>\n<li>Dictionaries \u2013 count the number of key-value pairs<\/li>\n<\/ul>\n<p><strong>Example:<br \/>\n<\/strong>len(&#8220;hello&#8221;) # Output: 5<br \/>\nlen((1, 2, 3)) # Output: 3<br \/>\nlen({&#8220;a&#8221;: 1, &#8220;b&#8221;: 2}) # Output: 2<\/p>\n<h5><strong>Conclusion<\/strong><\/h5>\n<\/div>\n<p>This article introduced various methods to determine the length of a list in Python.<\/p>\n<p>Find more information about <em><a href=\"https:\/\/www.bodhost.com\/kb\/how-to-check-python-version-in-linux-windows\/\" target=\"_blank\" rel=\"noopener\">how to check Python Version in Linux &amp; Windows<\/a><\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In Python, a list is a way to store multiple items in a single variable. For example, you might have a list of numbers, names, or even a mix of&hellip;<\/p>\n<p><a href=\"https:\/\/www.bodhost.com\/kb\/how-to-find-length-of-list-in-python\/\" class=\"more-link\">Read More<\/a><\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[837],"tags":[1623],"class_list":["post-14111","post","type-post","status-publish","format-standard","hentry","category-tutorial","tag-length-of-a-list-in-python"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Find the Length of a List in Python<\/title>\n<meta name=\"description\" content=\"Learn how to find the length of a list in Python using the len() function. Quickly determine the number of items in your list with this simple method.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.bodhost.com\/kb\/how-to-find-length-of-list-in-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Find the Length of a List in Python\" \/>\n<meta property=\"og:description\" content=\"Learn how to find the length of a list in Python using the len() function. Quickly determine the number of items in your list with this simple method.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.bodhost.com\/kb\/how-to-find-length-of-list-in-python\/\" \/>\n<meta property=\"og:site_name\" content=\"Knowledge Base - bodHOST\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-27T10:03:15+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-02-26T14:02:08+00:00\" \/>\n<meta name=\"author\" content=\"Paul Lopez\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Paul Lopez\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/how-to-find-length-of-list-in-python\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/how-to-find-length-of-list-in-python\\\/\"},\"author\":{\"name\":\"Paul Lopez\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#\\\/schema\\\/person\\\/566ccff9a2fae4af852be8097b179813\"},\"headline\":\"How to Find the Length of a List in Python\",\"datePublished\":\"2025-05-27T10:03:15+00:00\",\"dateModified\":\"2026-02-26T14:02:08+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/how-to-find-length-of-list-in-python\\\/\"},\"wordCount\":327,\"publisher\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#organization\"},\"keywords\":[\"Length of a List in Python\"],\"articleSection\":[\"Tutorial\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/how-to-find-length-of-list-in-python\\\/\",\"url\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/how-to-find-length-of-list-in-python\\\/\",\"name\":\"How to Find the Length of a List in Python\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#website\"},\"datePublished\":\"2025-05-27T10:03:15+00:00\",\"dateModified\":\"2026-02-26T14:02:08+00:00\",\"description\":\"Learn how to find the length of a list in Python using the len() function. Quickly determine the number of items in your list with this simple method.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/how-to-find-length-of-list-in-python\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/how-to-find-length-of-list-in-python\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/how-to-find-length-of-list-in-python\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Tutorial\",\"item\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/category\\\/tutorial\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Find the Length of a List in Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#website\",\"url\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/\",\"name\":\"Web Hosting Knowledge Base | bodHOST Hosting FAQ\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#organization\"},\"alternateName\":\"Web Hosting Knowledge Base | bodHOST Hosting FAQ\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#organization\",\"name\":\"Web Hosting Knowledge Base | bodHOST Hosting FAQ\",\"url\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/wp-content\\\/uploads\\\/2025\\\/10\\\/Profile-Pic.png\",\"contentUrl\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/wp-content\\\/uploads\\\/2025\\\/10\\\/Profile-Pic.png\",\"width\":240,\"height\":240,\"caption\":\"Web Hosting Knowledge Base | bodHOST Hosting FAQ\"},\"image\":{\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#\\\/schema\\\/logo\\\/image\\\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/#\\\/schema\\\/person\\\/566ccff9a2fae4af852be8097b179813\",\"name\":\"Paul Lopez\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c63d9f5400cd5ef87b481a24b2c1a4fb89f1674b6391325326cf13f1e735dff8?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c63d9f5400cd5ef87b481a24b2c1a4fb89f1674b6391325326cf13f1e735dff8?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/c63d9f5400cd5ef87b481a24b2c1a4fb89f1674b6391325326cf13f1e735dff8?s=96&d=mm&r=g\",\"caption\":\"Paul Lopez\"},\"url\":\"https:\\\/\\\/www.bodhost.com\\\/kb\\\/author\\\/paullopez\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Find the Length of a List in Python","description":"Learn how to find the length of a list in Python using the len() function. Quickly determine the number of items in your list with this simple method.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.bodhost.com\/kb\/how-to-find-length-of-list-in-python\/","og_locale":"en_US","og_type":"article","og_title":"How to Find the Length of a List in Python","og_description":"Learn how to find the length of a list in Python using the len() function. Quickly determine the number of items in your list with this simple method.","og_url":"https:\/\/www.bodhost.com\/kb\/how-to-find-length-of-list-in-python\/","og_site_name":"Knowledge Base - bodHOST","article_published_time":"2025-05-27T10:03:15+00:00","article_modified_time":"2026-02-26T14:02:08+00:00","author":"Paul Lopez","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Paul Lopez","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.bodhost.com\/kb\/how-to-find-length-of-list-in-python\/#article","isPartOf":{"@id":"https:\/\/www.bodhost.com\/kb\/how-to-find-length-of-list-in-python\/"},"author":{"name":"Paul Lopez","@id":"https:\/\/www.bodhost.com\/kb\/#\/schema\/person\/566ccff9a2fae4af852be8097b179813"},"headline":"How to Find the Length of a List in Python","datePublished":"2025-05-27T10:03:15+00:00","dateModified":"2026-02-26T14:02:08+00:00","mainEntityOfPage":{"@id":"https:\/\/www.bodhost.com\/kb\/how-to-find-length-of-list-in-python\/"},"wordCount":327,"publisher":{"@id":"https:\/\/www.bodhost.com\/kb\/#organization"},"keywords":["Length of a List in Python"],"articleSection":["Tutorial"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.bodhost.com\/kb\/how-to-find-length-of-list-in-python\/","url":"https:\/\/www.bodhost.com\/kb\/how-to-find-length-of-list-in-python\/","name":"How to Find the Length of a List in Python","isPartOf":{"@id":"https:\/\/www.bodhost.com\/kb\/#website"},"datePublished":"2025-05-27T10:03:15+00:00","dateModified":"2026-02-26T14:02:08+00:00","description":"Learn how to find the length of a list in Python using the len() function. Quickly determine the number of items in your list with this simple method.","breadcrumb":{"@id":"https:\/\/www.bodhost.com\/kb\/how-to-find-length-of-list-in-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.bodhost.com\/kb\/how-to-find-length-of-list-in-python\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.bodhost.com\/kb\/how-to-find-length-of-list-in-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Tutorial","item":"https:\/\/www.bodhost.com\/kb\/category\/tutorial\/"},{"@type":"ListItem","position":2,"name":"How to Find the Length of a List in Python"}]},{"@type":"WebSite","@id":"https:\/\/www.bodhost.com\/kb\/#website","url":"https:\/\/www.bodhost.com\/kb\/","name":"Web Hosting Knowledge Base | bodHOST Hosting FAQ","description":"","publisher":{"@id":"https:\/\/www.bodhost.com\/kb\/#organization"},"alternateName":"Web Hosting Knowledge Base | bodHOST Hosting FAQ","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.bodhost.com\/kb\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.bodhost.com\/kb\/#organization","name":"Web Hosting Knowledge Base | bodHOST Hosting FAQ","url":"https:\/\/www.bodhost.com\/kb\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.bodhost.com\/kb\/#\/schema\/logo\/image\/","url":"https:\/\/www.bodhost.com\/kb\/wp-content\/uploads\/2025\/10\/Profile-Pic.png","contentUrl":"https:\/\/www.bodhost.com\/kb\/wp-content\/uploads\/2025\/10\/Profile-Pic.png","width":240,"height":240,"caption":"Web Hosting Knowledge Base | bodHOST Hosting FAQ"},"image":{"@id":"https:\/\/www.bodhost.com\/kb\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/www.bodhost.com\/kb\/#\/schema\/person\/566ccff9a2fae4af852be8097b179813","name":"Paul Lopez","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/c63d9f5400cd5ef87b481a24b2c1a4fb89f1674b6391325326cf13f1e735dff8?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/c63d9f5400cd5ef87b481a24b2c1a4fb89f1674b6391325326cf13f1e735dff8?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c63d9f5400cd5ef87b481a24b2c1a4fb89f1674b6391325326cf13f1e735dff8?s=96&d=mm&r=g","caption":"Paul Lopez"},"url":"https:\/\/www.bodhost.com\/kb\/author\/paullopez\/"}]}},"_links":{"self":[{"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/posts\/14111","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/comments?post=14111"}],"version-history":[{"count":8,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/posts\/14111\/revisions"}],"predecessor-version":[{"id":14119,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/posts\/14111\/revisions\/14119"}],"wp:attachment":[{"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/media?parent=14111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/categories?post=14111"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bodhost.com\/kb\/wp-json\/wp\/v2\/tags?post=14111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}