In this article, we will discuss the concept of Python program to count the total number of characters in the given string
In this post, we are going to learn how to count the total number of characters in the given string in Python programming language
The program allows the user to enter a string and thereafter It counts the total characters of the string without space using for loop in Python language
Program 1
#Python program to count total characters of a given string str1=raw_input("Please enter your a string as you wish: ") count=0 for i in range(len(str1)): if(str1[i]!=' '):#avoid counting the space using this condition count=count+1 print("Total number of characters in this string: ",str(count));
When the above code is executed, it produces the following result
Please enter a string as you wish: python language Total number of characters in this string: 14
Program 2
#python program to count total number of character in a string str1=input("Enter a string as you wish \n"); total=0 for i in range(len(str1)): if(str1[i]!=' '): total=total+1 print("Total number of character in this string = ",total)
When the above code is executed, it produces the following result
Enter a string as you wish python language Total number of character in this string = 14
Approach
The program allows the user to enter a string and thereafter It counts the total characters of the string without space using while loop in Python language
Program 3
#python program to count total character of a String str1=input("Input a string as you wish: \n") total=0 i=0 while(i<len(str1)): if(str1[i]!=' '):#avoid counting the space using this condition total=total+1 i=i+1 print("total number of character in this string is: ", total)
When the above code is executed, it produces the following result
Input a string as you wish: python programming language total number of character in this string is: 25
Approach
Suggested for you
Similar post
Java program to count the total number of characters in the given string
C++ program to count the total number of characters in the given string
C program to count the total number of characters in the given string
PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…
PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…
5 methods to add two numbers in Java In this tutorial, we will discuss the…
Python full Pyramid star pattern program In this tutorial, we will discuss the concept of…
Write a function or method to convert C into F -Entered by the user In…
How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…