Computer Science - Class 12
Solutions to CBSE Sample Paper - Computer Science Class 12

(ii) To check whether a string named, message ends with a full stop / period or not.

Answer

Answer by student

The Python statement for checking whether a string named message ends with a full stop / period or not is:

message.endswith(“.”)

Detailed answer by teachoo

To write the Python statement for checking whether a string named message ends with a full stop / period or not, we need to understand the following concepts:

  • Strings are sequences of characters enclosed in quotes. We can access the individual characters of a string by using indexing , which starts from 0.
  • endswith() is a method that returns True if a string ends with a specified suffix, and False otherwise. The syntax of endswith() is string.endswith(suffix)
    • where suffix is the string to be checked as the end of the string. The suffix can be a single character or a substring. 
    • For example, message.endswith(“world.”) returns True if message ends with “world.”, and False otherwise.

Therefore, the Python statement for checking whether a string named message ends with a full stop / period or not is:

message.endswith(“.”)

Go Ad-free
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science, Social Science, Physics, Chemistry, Computer Science at Teachoo.