codescracker


python

Python Program to Find Length of String



« Previous Program Next Program »


Find Length of String in Python

To find length of any string in python, you have to ask from user to enter any string and then find the length of that string using the len() function as shown in the program given below.

Python Programming Code to Find Length of String

Following python program ask from user to enter a string and find the length of that string:

# Python Program - Find Length of String

print("Enter 'x' for exit.")
string = input("Enter a string to find its length: ")
if string == 'x':
    exit();
else:
    print("\nLength of the string =", len(string))

Here is the sample run of the above Python program:

find length of string python

Now enter any string say codescracker and press enter key to find its length or to find entered string's length as shown here:

length of string program python

Same program on python shell:

python find length of string

Same Program in Other Languages

You may also like to learn or practice the same program in other popular programming languages:


« Previous Program Next Program »








Tools
Calculator

Quick Links
Signup - Login - Give Online Test