Robotics & Artificial Intelligence

What would be the output of following program?

str2 = "My classmate is Aayan"
if str2.endswith("Aayan"): 
    print("Aayan is studying in class X") 
else: 
    print("Aayan is not the student of class X")

Python String Manipulation

1 Like

Answer

Output
Aayan is studying in class X
Explanation

The endswith() function returns True if the string ends with a particular suffix. Since the string "My classmate is Aayan" ends with "Aayan", the condition becomes true and the first print() statement is executed.

Answered By

1 Like


Related Questions