The method len() returns the number of elements in the list or length of the string depending upon the argument you are passing.
How to implement without using len():
1. Take input and pass the string/list into a function which return its length. 2. Initialize a count variable to 0, this count variable count character in the string. 3. Run a loop till length if the string and increment count by 1. 4. When loop is completed return count.
This article is contributed by Sahil Rajput. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Python | os.write() method
- Read, Write and Parse JSON using Python
- How to write an empty function in Python - pass statement?
- Python | Write multiple files data to master file
- Python | Create and write on excel file using xlsxwriter module
- Count of lines required to write the given String
- Python | Merge Python key values to list
- Python | Convert list to Python array
- Python | Index of Non-Zero elements in Python list
- Reading Python File-Like Objects from C | Python
- Important differences between Python 2.x and Python 3.x with examples
- Python | Set 4 (Dictionary, Keywords in Python)
- Python | Add Logging to Python Libraries
- Python | Sort Python Dictionaries by Key or Value
- Python | Add Logging to a Python Script