Loading section...

String Length with len()

This prints 13. The string has 13 characters: 5 letters in "Hello", a comma, a space, 5 letters in "World", and an exclamation mark. Empty Strings An empty string "" has length 0. It's a valid string that happens to contain no characters: The first prints 0. The second prints 3 because spaces count as characters. An empty string and a string of spaces are different! Practical Uses of len() This validates that a password has at least 8 characters. Length checking is essential for input validation, truncation, and many other string operations. Checking if a string is empty: