Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Python

Idiom #169 String length

Assign to the integer n the number of characters of the string s.
Make sure that multibyte characters are properly handled.
n can be different from the number of bytes of s.

n = len(s)

If s is a Python 3 str, len(s) returns the number of characters. If s is a Python 3 bytes, len(s) returns the number of bytes.
n : Integer := s'Length;

New implementation...