Python program to check if a given string starts with a specified character using lambda expression

Published by user on

In this post, we will see how to check if a given string starts with the specified character or not using lambda expression along with startswith(). startswith() function is an inbuilt function used to check if the string starts with the specified character or not.

Algorithm
Step 1: Declare a function starts_with string as a parameter
Step 2: Use startswith() to check if the provided string starts with the specified character or not
Step 3: Print True if the string starts with the specified character else print False
Step 4: End

Example

Input 
India
Output
England

Program

starts_with = lambda x: True if x.startswith('I') else False
print(starts_with(India))
starts_with = lambda x: True if x.startswith('X') else False
print(starts_with(England))

Output

True
False
Categories: python