Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
community creator

How to check the prefix and suffix using Python

Kamakolanu Srivalli Savitri Kalyani

Prefix

A prefix is the beginning letter of a word or group of words.

Example: The word “unhappy” consists of the prefix “un."

Given a query, string s, and a list of all possible words, return all words that have s as a prefix.

def prefix_words(prefix, word): 
    if word.startswith(prefix):
        print("Starts with {}").format(prefix)
prefix="un"
word="unhappy"
prefix_words(prefix,word)
Example of Prefix checking

Suffix

A suffix is a letter or group of letters added to the end of a word.

Example: Suffix ‘-ly’ is added to ‘quick’ to form ‘quickly’.

Given a query, string s, and a list of all possible words, return all words that have s as a suffix.

def suffix_words(suffix, word): 
    if word.endswith(suffix):
        print("Ends with {}").format(suffix)

suffix="ly"
word="quickly"
suffix_words(suffix, word)
Example of Suffix checking

RELATED TAGS

python
community creator

CONTRIBUTOR

Kamakolanu Srivalli Savitri Kalyani
RELATED COURSES

View all Courses

Keep Exploring