Write a Python program to calculate the length of a string


This program is written in Python and calculates the length of a string. The string "str" has a value "Tutor Joes". In the program, a variable "tot" is initialized to 0. This variable will be used to keep track of the number of characters in the string.

Next, a for loop is used to iterate through each character in the string "str". For each iteration, the value of "tot" is increased by 1 using the "+=" operator. Finally, the length of the string "str" is calculated by counting the number of iterations of the for loop, which is stored in the variable "tot". The program prints the length of the string using the "print()" function.

Source Code

"""
#First Method
str = "Tutor Joes"
print("Length of String :",len(str))
"""
#Second Method
str = "Tutor Joes"
tot = 0
for c in str:
	tot += 1
print("Length of String :",tot)

Output

Length of String : 10


Example Programs