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.
Python implementation:
# Function which return length of string def findLength(string): # Initialize count to zero count = 0 # Counting character in a string for i in string: count+= 1 # Returning count return count # Driver code string = "geeksforgeeks"print(findLength(string)) |
chevron_right
filter_none
Output:
13
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 contribute@geeksforgeeks.org. 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.
Recommended Posts:
- Print with your own font using Python !!
- Implement your own word2vec(skip-gram) model in Python
- Create your own universal function in NumPy
- Python String Methods | Set 2 (len, count, center, ljust, rjust, isalpha, isalnum, isspace & join)
- List Methods in Python | Set 1 (in, not in, len(), min(), max()...)
- Dictionary Methods in Python | Set 1 (cmp(), len(), items()...)
- Python string length | len()
- Python | Pandas Series.str.len()
- Internal Working of the len() Function in Python
- Change your way to put logic in your code - Python
- Program to print its own name as output
- Send mail from your Gmail account using Python
- Send mail with attachment from your Gmail account using Python
- Rename all file names in your directory using Python
- Python | Fetch your gmail emails from a particular user
- Get Your System Information - Using Python Script
- Customize your Python class with Magic or Dunder methods
- Python Script to Shutdown your PC using Voice Commands
- How to write an empty function in Python - pass statement?
- Python | Write multiple files data to master file

