 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Check if a string is suffix of another in Python
Suppose we have two strings s and t. We have to check whether s is suffix of t or not.
So, if the input is like s = "ate" t = "unfortunate", then the output will be True.
To solve this, we will follow these steps −
- s_len := size of s
- t_len := size of t
- if s_len > t_len, then- return False
 
- for i in range 0 to s_len, do- if s[s_len - i - 1] is not same as t[t_len - i - 1], then- return False
 
 
- if s[s_len - i - 1] is not same as t[t_len - i - 1], then
- return True
Let us see the following implementation to get better understanding −
Example
def solve(s, t): s_len = len(s) t_len = len(t) if (s_len > t_len): return False for i in range(s_len): if(s[s_len - i - 1] != t[t_len - i - 1]): return False return True s = "ate" t = "unfortunate" print(solve(s, t))
Input
"ate", "unfortunate"
Output
True
Advertisements
 