{"id":10210,"date":"2021-06-27T19:12:57","date_gmt":"2021-06-27T13:42:57","guid":{"rendered":"https:\/\/python-programs.com\/?p=10210"},"modified":"2021-11-22T18:38:34","modified_gmt":"2021-11-22T13:08:34","slug":"python-program-to-calculate-the-length-of-a-string-without-using-a-library-function","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-calculate-the-length-of-a-string-without-using-a-library-function\/","title":{"rendered":"Python Program to Calculate the Length of a String Without Using a Library Function"},"content":{"rendered":"

Strings in Python:<\/strong><\/p>\n

A string is one of the most frequent data types in any computer language. A string is a collection of characters that can be used to represent usernames, blog posts, tweets, or any other text content in your code. You can make a string and assign it to a variable by doing something like this.<\/p>\n

sample_string='BTechGeeks'<\/code><\/p>\n

Strings are considered immutable in Python, once created, they cannot be modified. You may, however, construct new strings from existing strings using a variety of approaches. This form of programming effort is known as string manipulation.<\/p>\n

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

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

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

given string = hello this is btechgeeks online<\/pre>\n

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

The length of given string { hello this is btechgeeks online } = 31<\/pre>\n

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

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

given string = for file operations upload files using 23199 -@33hello<\/pre>\n

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

The length of given string { for file operations upload files using 23199 -@33hello } = 54<\/pre>\n

Program to Calculate the Length of a String Without Using a Library Function in Python<\/h2>\n

Below is the full approach to calculate the length of the given string without using built-in library len() in Python.<\/p>\n