
Exercise 67
Write a Python function which takes as parameter a tuple of string (s , s1) and returns True if s start with s1 and False if not, without using the Python startswith() method.
Solution
def isStartWith(s ,s1):
n = len(s1)
if s[:n] == s1:
return True
else:
return False
# Example
s = "Python"
s1 = "Py"
print(isStartWith(s,s1)) # display: True
print(isStartWith(s,"Pi")) # display: False
Younes Derfoufi
my-courses.net
my-courses.net