(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(“.”)