Created
August 8, 2016 07:28
-
-
Save brainyfarm/003c8288dd2b971c9b40aa9970648066 to your computer and use it in GitHub Desktop.
FreeCodeCamp: Confirm the Ending (Python)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Check if a string (first argument, string) ends | |
| with the given target string (second argument, target). | |
| """ | |
| def confirmEnding(string, target): | |
| # Some intelligent stuff going on here | |
| # We fing out what part of string we need to compare with target | |
| start_reading_from = len(string) - len(target) | |
| # String slicing and comparing | |
| return string[start_reading_from:] == target | |
| print confirmEnding("Open sesame", "same") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment