Learn
Code Challenge: String Methods
Introduction
This lesson will help you review Python functions by providing some challenge exercises involving Strings.
As a refresher, function syntax looks like this:
def some_function(some_input1, some_input2): … do something with the inputs … return output
For example, a function that finds the difference in length between two Strings would look like this:
def lengthDiff(str1, str2): return len(str1) - len(str2)
And this would produce output like:
>>> lengthDiff("Python", "rocks") 1 >>> lengthDiff("Marco", "Polo") 1 >>> lengthDiff("Kevin", "Durant") -1
When you’re ready to do this series of short function challenges, continue on to the rest of the lesson!