Python String Length

Length is a property of a string. Through len function you can get the length of a string that means you can count the number of characters, of a particular string. If you want to count total characters of a string then you will have to pass your string as a parameter to len function which is built in Python function. This will return you total number of characters of string. The example of len function is mentioned below: Code


  StringVariable = "Hello All, this is a string example"
  # below mentioned statement shows you how to count total no. 
  # of characters of a string
  totalCharacter = len(StringVariable)
  print(totalCharacter)

In above mentioned example we have a string variable with the name of StringVariable. Then in other statement we tried to get total number of characters of StringVariable with the help of len function and store it to totalCharacter variable then we print totalCharacter variable.