Python Program to Find the Length of a String
In this tutorial, we will discuss a Python program to find the length of a string.
Related: Python Program to Find the Greatest of Three Numbers
Program code to find the length of a string in Python
# Find the Length of a String in Python def find_length(string): return len(string) input_string = input("Enter a string: ") length = find_length(input_string) print(f"The length of the string is {length}.")
Explanation
- Function Definition: The
find_length
function takes a string as input and returns its length using thelen()
function. - Main Program: The program prompts the user to enter a string and calculates its length using the
find_length
function. It then prints the result.
Output