Exercise 65
Write a Python program as function which takes as parameter a string s and returns True if the first character is the same as the last character of the string, False if not. Example if s = "render", the function must returns True. If s = "Python" the function returns False
Solution
def lastFirst(s):
if len(s) == 0:
return True
elif s[0] == s[-1]:
return True
else:
return False
# Example
print(lastFirst("render")) # display True
print(lastFirst("Python")) # display False
Younes Derfoufi
my-courses.net
my-courses.net