# some strings s = "immUTAble!" t = "banana" u = "AN" v = "an" w = "___" print( "s:", s ) print( "t:", t ) print( "u:", u ) print( "v:", v ) print( "w:", w ) print() # produce variants of a string s_c = s.capitalize() s_l = s.lower() s_u = s.upper() print( "s.lower() =", s_l, " # all lower case version of s" ) print( "s.upper() =", s_u, " # all upper case version of s" ) print( "s.capitalize() =", s_c, " # version of s initial character capitalized, rest lower" ) print() r1 = t.replace( u, w ) r2 = t.replace( v, w ) r3 = t.replace( v, "" ) print( "t.replace( u, w ):", r1, " # version of t with its u's replaced with w's" ) print( "t.replace( v, w ):", r2, " # version of t with its v's replaced with w's" ) print( "t.replace( v, \"\" ):", r3, " # version of t with its v's replaced with \"\"'s" ) print() # examine a string for its substrings c_u = t.count( u ) c_v = t.count( v ) c_v1 = t.count( v, 1 ) c_v2 = t.count( v, 2 ) c_v8 = t.count( v, 8 ) print( "t.count( u ):", c_u, " # number of string u in t" ) print( "t.count( v ):", c_v, " # number of string v in t" ) print() print( "t.count( v, 1 ):", c_v1, " # number of string v in t, starting at index 1" ) print( "t.count( v, 2 ):", c_v2, " # number of string v in t, starting at index 2" ) print( "t.count( v, 8 ):", c_v8, " # number of string v in t, starting at index 8" ) print() i_u = t.find( u ) i_v = t.find( v ) i_v1 = t.find( v, 1 ) i_v2 = t.find( v, 2 ) i_v8 = t.find( v, 8 ) print( "t.find( u ):", i_u, " # first occurrence of string u in t" ) print( "t.find( v ):", i_v, " # first occurrence of string v in t" ) print() print( "t.find( v, 1 ):", i_v1, " # first occurrence of string v in t, starting at index 1" ) print( "t.find( v, 2 ):", i_v2, " # first occurrence of string v in t, starting at index 2" ) print( "t.find( v, 8 ):", i_v8, " # first occurrence of string v in t, starting at index 8" )