Python startswith() and endswith()


Startswith & Endswith is used to verify if a string starts with a certain sequence of characters and endswith is used to verify if a string ends with a certain sequence of characters

>>> name='joko fani andrianto'
>>> print name
joko fani andrianto
>>>
>>> name.startswith('joko')
True
>>> name.startswith('andrianto')
False
>>>
>>>
>>> name.endswith('andrianto')
True
>>> name.endswith('joko')
False

This function is not return a string rather a boolean (bool) object which is true and false.

Tulis komentar anda... Conversion Conversion Emoticon Emoticon

Thanks for your comment