Unix -Python-courses-Solaris, Linux, FreeBSDPython-courses-python-exercises-python

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


def lastFirst(s):
if len(s) == 0:
return True
elif s[0] == s[-1]:
return True
return False

# Example
print(lastFirst("render")) # display True
print(lastFirst("Python")) # display False

Younes Derfoufi

Leave a Reply