TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Python String | endswith() method with Examples

Python String endswith() method with Examples on capitalize(), center(), count(), encode(), find(), format(), index(), join(), lower(), ljust(), isupper(), istitle(), isspace(), isprintable(), isnumeric(), islower() etc.

<< Back to PYTHON

Python String endswith() Method

Python endswith() method returns true of the string ends with the specified substring, otherwise returns false.

Signature

endswith(suffix[, start[, end]])

Parameters

  • suffix : a substring
  • start : start index of a range
  • end : last index of the range

Start and end both parameters are optional.

Return Type

It returns a boolean value either True or False.

Let's see some examples to understand the endswith() method.

Python String endswith() Method Example 1

A simple example which returns true because it ends with dot (.).

# Python endswith() function example
# Variable declaration
str = "Hello this is TheDeveloperBlog."
isends = str.endswith(".")
# Displaying result
print(isends)

Output:

True

Python String endswith() Method Example 2

It returns false because string does not end with is.

# Python endswith() function example
# Variable declaration
str = "Hello this is TheDeveloperBlog."
isends = str.endswith("is")
# Displaying result
print(isends)

Output:

False

Python String endswith() Method Example 3

Here, we are providing start index of the range from where method starts searching.

# Python endswith() function example
# Variable declaration
str = "Hello this is TheDeveloperBlog."
isends = str.endswith("is",10)
# Displaying result
print(isends)

Output:

False

Python String endswith() Method Example 4

It returns true because third parameter stopped the method at index 13.

# Python endswith() function example
# Variable declaration
str = "Hello this is TheDeveloperBlog."
isends = str.endswith("is",0,13)
# Displaying result
print(isends)

Output:

True

Next TopicPython Strings




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf