Logo

Programming-Idioms

History of Idiom 169 > diff from v95 to v96

Edit summary for version 96 by programming-idioms.org:
[Python] +DemoURL

Version 95

2021-12-13, 13:41:54

Version 96

2021-12-23, 09:10:31

Idiom #169 String length

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

Idiom #169 String length

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

Variables
n,s
Variables
n,s
Extra Keywords
size characters chars number runes
Extra Keywords
size characters chars number runes
Code
n = len(s)
Code
n = len(s)
Comments bubble
If s is a Python 3 str, or a Python 2 unicode, len(s) returns the number of characters. If s is a Python 2 str or a Python 3 bytes, len(s) returns the number of bytes.
Comments bubble
If s is a Python 3 str, or a Python 2 unicode, len(s) returns the number of characters. If s is a Python 2 str or a Python 3 bytes, len(s) returns the number of bytes.
Demo URL
https://replit.com/@ProgIdioms/GummyStaleContent#main.py