Built-in class str


Purpose


Link(s)


Suppose

a = 'abcdefghijklm'

b = 'Abra-Ca-Dabra!!'

c = 'ra'

d = '314159'

e = '3.1415'

f = 'cs 1112'


Built-in function and operators

len( s )

str( n )

Returns '12345'.

Returns '12.345'.

[ i : j ]

[ i : ]

[ : j ]

[ i ]

[ : ]


Essential member methods

capitalize()

count( s )

count( s, i, j )

find( s )

find( s, i )

find( s, i, j )

format( v1, v2, ... )

isalpha()

Returns True as all characters in 'abcdefghijklm' are alphabetic.

Returns False as not all characters in 'Abra-Ca-Dabra!!' are alphabetic.

isdigit()

Returns True as all characters in '314159' are digits.

Returns False not all characters in '3.1415' are digits.

lower()

Returns abra-ca-dabra!!.

replace( s, t, n )

Returns 'Abr___-C___-D___br___!!'. All occurrences of 'a' in 'Abra-Ca-Dabra!!' are replaced with '___'. Note, 'A' is not changed.

Returns 'Abr___-C___-Dabra!!'. The first two occurrences of 'a' in 'Abra-Ca-Dabra!!' are replaced with '___'.

rfind( s )

Returns 11. Last occurrence of 'ra' in 'Abra-Ca-Dabra!!' is at index 11.

rfind( s, i, j )

Returns 2. The last occurrence of 'ra' in 'Abra-Ca-Dabra!!' in index interval [ 1, 14 ) is 2.

split()

Returns the list [ 'cs', '1112' ].

split( d )

Returns the list [ 'Abr', '-C', '-D', 'br', '!!' ].

strip()

Returns the string `'cs 1112'``.

Returns the string `'cdefghijkl'``.

upper()

Returns ABRA-CA-DABRA!!.