Length of String

Find and print the length of a string.

Logic BuildingBeginner
Logic Building
# Take string input
s = input("Enter a string: ")

# Get length
length = len(s)
print(f"Length: {length}")

Output

Enter a string: Hello
Length: 5

Use len() function to get string length.

Key Concepts:

  • len(s) returns number of characters
  • Includes spaces and special characters
  • Empty string has length 0