{"id":9736,"date":"2021-03-07T19:04:43","date_gmt":"2021-03-07T13:34:43","guid":{"rendered":"http:\/\/www.pythonpool.com\/?p=9736"},"modified":"2021-06-14T15:11:50","modified_gmt":"2021-06-14T09:41:50","slug":"python-string-length","status":"publish","type":"post","link":"https:\/\/www.pythonpool.com\/python-string-length\/","title":{"rendered":"5 Best Ways to Find Python String Length"},"content":{"rendered":"\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_74 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #990303;color:#990303\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #990303;color:#990303\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.pythonpool.com\/python-string-length\/#What_is_Python_String_Length\" >What is Python String Length?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.pythonpool.com\/python-string-length\/#Syntax\" >Syntax<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.pythonpool.com\/python-string-length\/#Parameters\" >Parameters<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.pythonpool.com\/python-string-length\/#Return_Value\" >Return Value<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.pythonpool.com\/python-string-length\/#Ways_to_find_the_length_of_string_in_Python\" >Ways to find the length of string in Python<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.pythonpool.com\/python-string-length\/#1_Using_the_built-in_function_len\" >1. Using the built-in function len()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.pythonpool.com\/python-string-length\/#2_Using_for_loop_to_Find_the_length_of_the_string_in_python\" >2. Using for loop to Find the length of the string in python<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.pythonpool.com\/python-string-length\/#3_Using_while_loop_and_Slicing\" >3. Using while loop and Slicing<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.pythonpool.com\/python-string-length\/#4_Using_string_methods_join_and_count\" >4. Using string methods join and count<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.pythonpool.com\/python-string-length\/#5_Using_getsizeof_method_to_Find_Length_Of_String_In_Python\" >5. Using getsizeof() method to Find Length Of String In Python<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.pythonpool.com\/python-string-length\/#Example_to_Find_Length_of_String_in_Python\" >Example to Find Length of String in Python<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.pythonpool.com\/python-string-length\/#Must_Read\" >Must Read<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/www.pythonpool.com\/python-string-length\/#Summary_Python_String_Length\" >Summary: Python String Length<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"h-what-is-python-string-length\"><span class=\"ez-toc-section\" id=\"What_is_Python_String_Length\"><\/span>What is Python String Length?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Python string length is the function through which we find the length of the string. There is an inbuilt function called len() in python, so this len() function finds the length of the given string, array, <a href=\"http:\/\/www.pythonpool.com\/python-list-length\/\" target=\"_blank\" rel=\"noreferrer noopener\">list<\/a>, tuple, dictionary, etc.<\/p>\n\n\n\n<p>Through the len() function, we can 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.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-syntax\"><span class=\"ez-toc-section\" id=\"Syntax\"><\/span>Syntax<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nlen(string)\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-parameters\"><span class=\"ez-toc-section\" id=\"Parameters\"><\/span>Parameters<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><strong>String : <\/strong> This will calculate the length of the value passed in the string variable. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-return-value\"><span class=\"ez-toc-section\" id=\"Return_Value\"><\/span>Return Value<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>It will return an interger value i.e.  the length of the given string.<\/p>\n\n\n\n<p><strong>Various Type Of Return Value<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>String<\/li><li>Empty<\/li><li>Collection<\/li><li>Type Error<\/li><li>Dictionary<\/li><\/ol>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-1-string\">1. String: <\/h3>\n\n\n\n<p>It is used to return the number of characters present in the string, including <a href=\"http:\/\/www.pythonpool.com\/remove-punctuation-python\/\" target=\"_blank\" rel=\"noopener\">punctuation<\/a>, space, and all types of special characters. However, it would help if you were careful while using the len of a Null variable.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-2-empty\">2. Empty:<\/h3>\n\n\n\n<p>In this the return call has the zero characters, but it is always None.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-3-collections\">3. Collections:<\/h3>\n\n\n\n<p>The len() built in function return the number of elements in the collection.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-4-type-error\">4. Type Error:<\/h3>\n\n\n\n<p>Len function always depends on the type of the variable passed to it. A Non-Type len() does not have any built-in support.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-5-dictionary\">5. Dictionary:<\/h3>\n\n\n\n<p>In this, each pair is counted as one unit. However, Keys and values are not independent in the dictionary.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-ways-to-find-the-length-of-string-in-python\"><span class=\"ez-toc-section\" id=\"Ways_to_find_the_length_of_string_in_Python\"><\/span>Ways to find the length of string in Python<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"683\" height=\"385\" src=\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/03\/Ways-to-find-the-length-of-string.jpg\" alt=\"Ways to find the length of string\" class=\"wp-image-9878\" srcset=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/03\/Ways-to-find-the-length-of-string.jpg 683w, https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/03\/Ways-to-find-the-length-of-string-300x169.jpg 300w\" sizes=\"(max-width: 683px) 100vw, 683px\" \/><\/figure><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-1-using-the-built-in-function-len\"><span class=\"ez-toc-section\" id=\"1_Using_the_built-in_function_len\"><\/span>1. Using the built-in function len()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n# Python code to demonstrate string length  \n# using len \n\nstr = 'Latracal'\nprint(len(str))\n<\/pre><\/div>\n\n\n<p><strong> output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>8<\/code><\/pre>\n\n\n\n<p><strong>Explanation:<\/strong><\/p>\n\n\n\n<p>In this code, we have taken str as the variable in which we have stored the string named &#8216;Latracal&#8217; and then applied the len() in which we have put str in between. so the output came is 8 as the word &#8216;<a href=\"https:\/\/latracal.com\/\" target=\"_blank\" rel=\"noreferrer noopener\">Latracal<\/a>&#8216; contains 8 characters.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-2-using-for-loop-to-find-the-length-of-the-string-in-python\"><span class=\"ez-toc-section\" id=\"2_Using_for_loop_to_Find_the_length_of_the_string_in_python\"><\/span>2. Using for loop to Find the length of the string in python<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>&nbsp;A string can be <a href=\"http:\/\/www.pythonpool.com\/python-iterate-through-list\/\" target=\"_blank\" rel=\"noreferrer noopener\">iterated<\/a> over easily and directly in for loop. By maintaining a count of the number of iterations will result in the length of the string.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n# Python code to demonstrate string length  \n# using for loop \n  \n# Returns length of string \ndef findLength(str): \n    counter = 0    \n    for i in str: \n        counter += 1\n    return counter \n  \n  \nstr = &quot;Latracal&quot;\nprint(findLength(str))\n<\/pre><\/div>\n\n\n<p><strong>output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>8<\/code><\/pre>\n\n\n\n<p><strong>Explanation:<\/strong><\/p>\n\n\n\n<p>In this code, we have used for loop to find the length of the string. Firstly, we have taken an str variable that we have given &#8216;Latracal&#8217; as the string. Secondly, we have called the findLength function in which we have counter equals 0, After that, for loop was written from 0 to string, and the counter value gets increased by 1 at a time. At last, we have printed the counter value.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-3-using-while-loop-and-slicing\"><span class=\"ez-toc-section\" id=\"3_Using_while_loop_and_Slicing\"><\/span>3. Using while loop and Slicing<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>We slice a string making it shorter by 1 at regular intervals to time with each iteration till the string is the empty string. This is when the while loop stops. By maintaining a count of the number of iterations will result in the length of the string.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n# Python code to demonstrate string length  \n# using while loop. \n  \n# Returns length of string \ndef findLength(str): \n    count = 0\n    while str&#x5B;count:]: \n        count = count + 1\n    return count \n  \nstr = &quot;LatracalSolutions&quot;\nprint(findLength(str)) \n<\/pre><\/div>\n\n\n<p><strong>output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>17<\/code><\/pre>\n\n\n\n<p><strong>Explanation:<\/strong><\/p>\n\n\n\n<p>In this code, we have used for loop to find the length of the string. Firstly, we have taken an str variable in which we have given &#8216;LatracalSolutions&#8217; as the string. Secondly, we have called the findLength function in which we have set the value of count equals 0. Thirdly, then applied the while loop in which we are slicing the value of str by one at each iteration till the string becomes empty. And at last, returned the count value.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-4-using-string-methods-join-and-count\"><span class=\"ez-toc-section\" id=\"4_Using_string_methods_join_and_count\"><\/span>4. Using string methods join and count<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The join method of strings takes in an iteration and returns a string which is the concatenation of the iteration strings. The separator present in the between of elements is the original string on which the method is called. Using the join and count method, the joined string in the original string will also result in the string&#8217;s length.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n# Python code to demonstrate string length  \n# using join and count \n  \n# Returns length of string \ndef findLength(str): \n    if not str: \n        return 0\n    else: \n        some_random_str = 'py'\n        return ((some_random_str).join(str)).count(some_random_str) + 1\n  \nstr = &quot;LatracalSolutions&quot;\nprint(findLength(str))\n<\/pre><\/div>\n\n\n<p><strong>output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>17<\/code><\/pre>\n\n\n\n<p><strong>Explanation:<\/strong><\/p>\n\n\n\n<p>In this code, we have used for loop to find the length of the string. Firstly, we have taken an str variable in which we have given &#8216;LatracalSolutions&#8217; as the string. Secondly, then we have called the findLength function in which we have applied if and else function in which if contains the conditions that if the string is empty, it should return 0; otherwise, the else part will work. We have taken some random string &#8216;py&#8217; in which the main string will get join by the iteration, and the count value will increase till the string becomes empty. After that, the output gets printed.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-5-using-getsizeof-method-to-find-length-of-string-in-python\"><span class=\"ez-toc-section\" id=\"5_Using_getsizeof_method_to_Find_Length_Of_String_In_Python\"><\/span>5. Using getsizeof() method to Find Length Of String In Python<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>This method is used to find the object&#8217;s storage size that occupies some space in the memory. <\/p>\n\n\n\n<p class=\"has-vivid-green-cyan-background-color has-background\"><strong>Note<\/strong>: This method is only applicable for normal ascii letters. If you have a special character it&#8217;ll not work, as it uses the size of the string in bytes. So be careful while using it!<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport sys\ns = &quot;pythonpool&quot;\nprint(sys.getsizeof(s) - sys.getsizeof(&quot;&quot;))\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>10<\/code><\/pre>\n\n\n\n<p><strong>Explanation:<\/strong><\/p>\n\n\n\n<p>Here, we have used the sys module which is inbuilt in python. then we have to take a string s and using the sys module with the getsizeof() method printed the length of the string.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-example-to-find-length-of-string-in-python\"><span class=\"ez-toc-section\" id=\"Example_to_Find_Length_of_String_in_Python\"><\/span>Example to Find Length of String in Python<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n# Python code to demonstrate string length\n# testing len() \nstr1 = &quot;Welcome to Latracal Solutions Python Tutorials&quot;\nprint(&quot;The length of the string  is :&quot;, len(str1))\n<\/pre><\/div>\n\n\n<p><strong>Output:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>The length of the string  is : 46<\/code><\/pre>\n\n\n\n<h2 class=\"has-vivid-red-color has-text-color wp-block-heading\" id=\"h-must-read\"><span class=\"ez-toc-section\" id=\"Must_Read\"><\/span>Must Read<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-yoast-seo-related-links\"><li><a href=\"http:\/\/www.pythonpool.com\/python-list-length\/\">Python List Length | How to Find the Length of List in Python<\/a><\/li><li><a href=\"http:\/\/www.pythonpool.com\/python-check-if-list-is-empty\/\">How to Check If List is Empty in Python With Examples<\/a><\/li><li><a href=\"http:\/\/www.pythonpool.com\/python-list-index-out-of-range\/\">Python list index out of range: Error and Resolution<\/a><\/li><li><a href=\"http:\/\/www.pythonpool.com\/python-sort-list-of-lists\/\">6 Unique Ways in Python to Sort the List of Lists<\/a><\/li><li><a href=\"http:\/\/www.pythonpool.com\/python-float-to-string\/\">Python float to string Conversion Using 10 Different Methods<\/a><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-summary-python-string-length\"><span class=\"ez-toc-section\" id=\"Summary_Python_String_Length\"><\/span>Summary: Python String Length<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>We&#8217;ve seen all 5 different ways of finding the string length, but in conclusion, only one of them is practical. In-built len() keyword is the best way to find the length of the string in any type of format.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>Python len()<\/strong> is a built-in function. You can use the len() to find the length of the given string, array, list, tuple, dictionary, etc.<\/li><li><strong>String:<\/strong> This will calculate the length of the value passed in the string variable.<\/li><li><strong>Return value:<\/strong> It will return an integer value i.e. the length of the given string.<\/li><\/ul>\n\n\n\n<p>However, if you have any doubts or questions, do let me know in the comment section below. I will try to help you as soon as possible.<\/p>\n\n\n\n<p><strong><em>Happy Pythoning!<\/em><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>What is Python String Length? Python string length is the function through which we find the length of the string. There is an inbuilt function &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"5 Best Ways to Find Python String Length\" class=\"read-more button\" href=\"https:\/\/www.pythonpool.com\/python-string-length\/#more-9736\" aria-label=\"More on 5 Best Ways to Find Python String Length\">Read more<\/a><\/p>\n","protected":false},"author":17,"featured_media":9880,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[15],"tags":[3688,3693,3686,3692,3690,3685],"class_list":["post-9736","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","tag-get-length-of-string-python","tag-length-of-a-string-python","tag-length-of-string-python","tag-python-length-of-string","tag-string-length-in-python","tag-string-length-python","infinite-scroll-item"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v20.1 (Yoast SEO v25.0) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>5 Best Ways to Find Python String Length - Python Pool<\/title>\n<meta name=\"description\" content=\"The inbuilt python len() is used to find the length of the string, array, list, tuple etc which optimises the performance of the program.\" \/>\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.pythonpool.com\/python-string-length\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"5 Best Ways to Find Python String Length\" \/>\n<meta property=\"og:description\" content=\"What is Python String Length? Python string length is the function through which we find the length of the string. There is an inbuilt function called\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pythonpool.com\/python-string-length\/\" \/>\n<meta property=\"og:site_name\" content=\"Python Pool\" \/>\n<meta property=\"article:published_time\" content=\"2021-03-07T13:34:43+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-06-14T09:41:50+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/03\/python-string-length.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1350\" \/>\n\t<meta property=\"og:image:height\" content=\"650\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Siddharth Jain\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:site\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Siddharth Jain\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.pythonpool.com\/python-string-length\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-string-length\/\"},\"author\":{\"name\":\"Siddharth Jain\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/75a3240fabe5ea90200777a9d8d3b4fa\"},\"headline\":\"5 Best Ways to Find Python String Length\",\"datePublished\":\"2021-03-07T13:34:43+00:00\",\"dateModified\":\"2021-06-14T09:41:50+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-string-length\/\"},\"wordCount\":1001,\"commentCount\":3,\"publisher\":{\"@id\":\"https:\/\/www.pythonpool.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-string-length\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/03\/python-string-length.png\",\"keywords\":[\"get length of string python\",\"length of a string python\",\"length of string python\",\"python length of string\",\"string length in python\",\"string length python\"],\"articleSection\":[\"Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.pythonpool.com\/python-string-length\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.pythonpool.com\/python-string-length\/\",\"url\":\"https:\/\/www.pythonpool.com\/python-string-length\/\",\"name\":\"5 Best Ways to Find Python String Length - Python Pool\",\"isPartOf\":{\"@id\":\"https:\/\/www.pythonpool.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-string-length\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-string-length\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/03\/python-string-length.png\",\"datePublished\":\"2021-03-07T13:34:43+00:00\",\"dateModified\":\"2021-06-14T09:41:50+00:00\",\"description\":\"The inbuilt python len() is used to find the length of the string, array, list, tuple etc which optimises the performance of the program.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-string-length\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.pythonpool.com\/python-string-length\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/python-string-length\/#primaryimage\",\"url\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/03\/python-string-length.png\",\"contentUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/03\/python-string-length.png\",\"width\":1350,\"height\":650,\"caption\":\"Python String Length\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.pythonpool.com\/python-string-length\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.pythonpool.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"5 Best Ways to Find Python String Length\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.pythonpool.com\/#website\",\"url\":\"https:\/\/www.pythonpool.com\/\",\"name\":\"Python Pool\",\"description\":\"Your One-Stop Python Learning Destination\",\"publisher\":{\"@id\":\"https:\/\/www.pythonpool.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.pythonpool.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.pythonpool.com\/#organization\",\"name\":\"Python Pool\",\"url\":\"https:\/\/www.pythonpool.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/\",\"url\":\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png\",\"contentUrl\":\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png\",\"width\":452,\"height\":185,\"caption\":\"Python Pool\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/pythonpool\",\"https:\/\/www.youtube.com\/c\/pythonpool\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/75a3240fabe5ea90200777a9d8d3b4fa\",\"name\":\"Siddharth Jain\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/152b0ac2e5fa2e6328f374499fff4a7a6299477b9cf7bbb15ebc01a88f8f673f?s=96&d=wavatar&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/152b0ac2e5fa2e6328f374499fff4a7a6299477b9cf7bbb15ebc01a88f8f673f?s=96&d=wavatar&r=g\",\"caption\":\"Siddharth Jain\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"5 Best Ways to Find Python String Length - Python Pool","description":"The inbuilt python len() is used to find the length of the string, array, list, tuple etc which optimises the performance of the program.","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.pythonpool.com\/python-string-length\/","og_locale":"en_US","og_type":"article","og_title":"5 Best Ways to Find Python String Length","og_description":"What is Python String Length? Python string length is the function through which we find the length of the string. There is an inbuilt function called","og_url":"https:\/\/www.pythonpool.com\/python-string-length\/","og_site_name":"Python Pool","article_published_time":"2021-03-07T13:34:43+00:00","article_modified_time":"2021-06-14T09:41:50+00:00","og_image":[{"width":1350,"height":650,"url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/03\/python-string-length.png","type":"image\/png"}],"author":"Siddharth Jain","twitter_card":"summary_large_image","twitter_creator":"@pythonpool","twitter_site":"@pythonpool","twitter_misc":{"Written by":"Siddharth Jain","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pythonpool.com\/python-string-length\/#article","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/python-string-length\/"},"author":{"name":"Siddharth Jain","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/75a3240fabe5ea90200777a9d8d3b4fa"},"headline":"5 Best Ways to Find Python String Length","datePublished":"2021-03-07T13:34:43+00:00","dateModified":"2021-06-14T09:41:50+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pythonpool.com\/python-string-length\/"},"wordCount":1001,"commentCount":3,"publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"image":{"@id":"https:\/\/www.pythonpool.com\/python-string-length\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/03\/python-string-length.png","keywords":["get length of string python","length of a string python","length of string python","python length of string","string length in python","string length python"],"articleSection":["Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pythonpool.com\/python-string-length\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pythonpool.com\/python-string-length\/","url":"https:\/\/www.pythonpool.com\/python-string-length\/","name":"5 Best Ways to Find Python String Length - Python Pool","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pythonpool.com\/python-string-length\/#primaryimage"},"image":{"@id":"https:\/\/www.pythonpool.com\/python-string-length\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/03\/python-string-length.png","datePublished":"2021-03-07T13:34:43+00:00","dateModified":"2021-06-14T09:41:50+00:00","description":"The inbuilt python len() is used to find the length of the string, array, list, tuple etc which optimises the performance of the program.","breadcrumb":{"@id":"https:\/\/www.pythonpool.com\/python-string-length\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pythonpool.com\/python-string-length\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/python-string-length\/#primaryimage","url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/03\/python-string-length.png","contentUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2021\/03\/python-string-length.png","width":1350,"height":650,"caption":"Python String Length"},{"@type":"BreadcrumbList","@id":"https:\/\/www.pythonpool.com\/python-string-length\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pythonpool.com\/"},{"@type":"ListItem","position":2,"name":"5 Best Ways to Find Python String Length"}]},{"@type":"WebSite","@id":"https:\/\/www.pythonpool.com\/#website","url":"https:\/\/www.pythonpool.com\/","name":"Python Pool","description":"Your One-Stop Python Learning Destination","publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pythonpool.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.pythonpool.com\/#organization","name":"Python Pool","url":"https:\/\/www.pythonpool.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/","url":"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","contentUrl":"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","width":452,"height":185,"caption":"Python Pool"},"image":{"@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/pythonpool","https:\/\/www.youtube.com\/c\/pythonpool"]},{"@type":"Person","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/75a3240fabe5ea90200777a9d8d3b4fa","name":"Siddharth Jain","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/152b0ac2e5fa2e6328f374499fff4a7a6299477b9cf7bbb15ebc01a88f8f673f?s=96&d=wavatar&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/152b0ac2e5fa2e6328f374499fff4a7a6299477b9cf7bbb15ebc01a88f8f673f?s=96&d=wavatar&r=g","caption":"Siddharth Jain"}}]}},"_links":{"self":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/9736","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/users\/17"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/comments?post=9736"}],"version-history":[{"count":30,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/9736\/revisions"}],"predecessor-version":[{"id":24472,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/9736\/revisions\/24472"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media\/9880"}],"wp:attachment":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media?parent=9736"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/categories?post=9736"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/tags?post=9736"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}