Codeforcoding

Program to count the total number of characters in the given string with space in Python

Program to count the total number of characters in the given string in Python

In this article, we will discuss the concept of the Program to count the total number of characters  including space of the given string in Python

In this post, we are going to learn how to count the total number of character including space of the given string in Python programming language

Program to count the total number of characters in the given string with space in Python
Count characters

Code to count the total number of characters in the given string

Code to count the total number of characters using for loop

The program allows the user to enter a String and then it counts and display the number of characters including space of the given string using for loop in Python programing language

Program 1

#Python program to count total characters of a given string
str1=raw_input("Please enter your a string as you wish: ")
total=0
for i in str1:
    total=total+1;
print("Total number of characters in this string: ",total)

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: 15

Code to count the total number of characters using len() function

The program allows the user to enter a String and then it counts and display the number of characters including space of the given string using len()  function in Python programing language

Program 2

#Python program to count total characters of a given string
str1=raw_input("Please enter your a string as you wish: ")
total=0

for i in range(len(str1)):
    total=total+1;
    i=i+1
print("Total number of characters in this string: ",total)

When the above code is executed, it produces the following result

Please enter a string as you wish: Python programming
Total number of characters in this string:  18

 

Code to count the total number of characters using while loop

The program allows the user to enter a String and then it counts and display the number of characters including space of the given string using while loop in Python programing language

Program 3

#Python program to count total characters of a given string
str1=raw_input("Please enter your a string as you wish: ")
total=0
i=0

while(i<len(str1)):
    total=total+1;
    i=i+1
print("Total number of characters in this string: ",total)

When the above code is executed, it produces the following result

Please enter a string as you wish: Code4coding.com
Total number of characters in this string: 15

 

Suggested for you

for loop in Python language

while loop in Python language

 

Similar post

C++  code to count the total number of characters in the given string

C code to count the total number of characters in the given string

Python code to count the total number of characters in the given string

 

Java program to count the total number of characters in the given string including space

C program to count the total number of characters in the given string including space

C++ program to count the total number of characters in the given string including space

 

C++ program to count the total number of characters in the given string including space
Count Uppercase, Lowercase,Special character and Numeric values in Java
Exit mobile version