Topic: Find Length of String without using len() in Python.
Hey Guys, today we are going see a Python Program to find the length of a string without using the built-in len() function.
Title: Python Code to Find Length of String without len(). (Beginner Friendly + Easy + Code + Output + Online Compiler)
What is this program and why we are going to use it?
This Program consists of Variables, Input Function and Loop (for loop).
By using variables, we store string input from the user. By using input function, we take input from the user. For example:
s = "hello"
Here s is a variable where "hello" is assigned to s.
Instead of using len(), we manually count each character.
By using variables, we store string input from the user. By using input function, we take input from the user. For example:
s = "hello"
Here s is a variable where "hello" is assigned to s.
Instead of using len(), we manually count each character.
s = input("Enter a string: ")
So, this will ask user to input a string.
Logic:
1. Take a string (s) from user.
2. Initialize count = 0.
3. Loop through each character in string.
- Increment count by 1 for each character
4. Display total length.
Code:
Online Compiler (Switch to Interactive Mode before execution):
Example Output:
Input: hello
Output: Length of string: 5
Output: Length of string: 5
Applications:
1. Helps in understanding loops and iteration
2. Useful for logic building without built-in functions
3. Used in low-level string processing concepts
2. Useful for logic building without built-in functions
3. Used in low-level string processing concepts
Comments
Post a Comment