December 2000
Intermediate to advanced
816 pages
16h 57m
English
As with the value comparison operators, the cmp() built-in function also performs a lexicographic comparison for strings.
>>> str1 = 'abc' >>> str2 = 'lmn' >>> str3 = 'xyz' >>> cmp(str1, str2) -11 >>> cmp(str3, str1) 23 >>> cmp(str2, 'lmn') 0
>>> str1 = 'abc'
>>> len(str1)
3
>>> len('Hello World!')
12
The len() built-in function returns the number of characters in the string as expected.
>>> str2 = 'lmn' >>> str3 = 'xyz' >>> max(str2) 'n' >>> min(str3) 'x'
Although more useful with other sequence types, the max() and min() built-in functions do operate as advertised, returning the greatest and least characters (lexicographic ...
Read now
Unlock full access