# string functions # indexing/slicing name = "Ben Bitdiddle" print name[0] print name[0:3] print name [4:] # other cool methods print name.lower() print name.upper() print name.count("d") print name.split(" ") # note: strings are immutable print name.lower() print name long_name = name long_name += " The Third" print name print long_name print name[0] name[0] = "K" # error # membership testing print "B" in name print "k" in name # while not (user_input in ["yes", "no", "maybe"]): #ask for user input # tuples # tuple unpacking position = (1, 1, 2) x, y, z = position print x, y, z print position[0] position[0] = 5 # error # lists # just like tuples, but mutable flavors = ["vanilla", "chocolate", "mint"] print flavors print flavors[0] #edit entries flavors[2] = "strawberry" #add entries flavors.append("watermelon") print flavors #note: return types new_flavors = flavors.append("banana") print new_flavors print flavors #delete entries flavors.pop(0) print flavors # aliasing l1 = [1, 2, 3] l2 = l1 l2.append(4) print l2 print l1