Write a python program startswith and Endswith Methods
Using startswith()
def myfun():
list1 = ['lemon','orange','apple', 'banana', 'apricot']
list2=[i for i in list1 if i.startswith('a')]
print(list2)
if __name__=="__main__":
myfun()
Output:
['apple', 'apricot']
Using endswith()
def myfun():
list1 = ['lemon','orange','apple', 'banana', 'apricot']
list2=[i for i in list1 if i.endswith('e')]
print(list2)
if __name__=="__main__":
myfun()
Output:
['orange', 'apple']
More Questions
39 . Write a python program startswith and Endswith Methods
40 . Write a python program to print Nlargest numbers
41 . Write a python program to print Nsmallest numbers
42 . Write a python program to check two strings are Anagram or not
43 . Write a python program to checking internet speed
44 . Write a python program to print reserved keywords
45 . Write a python program to print properties and methods
46 . Write a python program to open a website using python
47 . Write a python program to print most frequent letter in a string
48 . Write a python program to check memory sizes of list ,set ,tuple
49 . How do you confirm if an object is iterable using code?
For latest job updates join Telegram Channel: https://t.me/sateeshm