Logo

Programming-Idioms

History of Idiom 169 > diff from v96 to v97

Edit summary for version 97 by programming-idioms.org:
[Python] Python 2 is deprecated, see issues/184

Version 96

2021-12-23, 09:10:31

Version 97

2021-12-23, 09:11:52

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, len(s) returns the number of characters. If s is a Python 3 bytes, len(s) returns the number of bytes.
Demo URL
https://replit.com/@ProgIdioms/GummyStaleContent#main.py
Demo URL
https://replit.com/@ProgIdioms/GummyStaleContent#main.py