Page 232 - Robotics and AI class 10
P. 232
String in-built Functions/Methods
Function Description Example
len() It returns the total number of >>> TXT="PROGRAMMING IS AMAZING"
characters in the string >>> len(TXT)
22
upper() It displays the string in uppercase >>> TXT="PROGRAMMING IS AMAZING"
>>> TXT.upper()
'PROGRAMMING IS AMAZING'
>>> 'hello'.upper()
'HELLO'
lower() It displays the string in lowercase >>> TXT="PROGRAMMING IS AMAZING"
>>> TXT.lower()
'programming is amazing'
>>> TXT
'PROGRAMMING IS AMAZING'
title() It displays the first letter of every word >>> TXT="PROGRAMMING IS AMAZING"
in uppercase and remaining in small >>> TXT.title()
'Programming Is Amazing'
capitalize() It displays the first letter of first word >>> TXT="PROGRAMMING IS AMAZING"
in uppercase and remaining in small >>> TXT.capitalize()
'Programming is amazing'
startswith() It returns True if a string starts with >>> "Hello, how are you?".
the specified substring startswith('Hello')
True
>>> "Hello, how are you?".
startswith('hello')
False
>>> "Hello, how are you?".startswith('He')
True
endswith() It returns True if a string ends with >>> "Hello, how are you?".endswith('you')
the specified substring False
>>> "Hello, how are you?".endswith('you?')
True
>>> "Hello, how are you?".endswith('u?')
True
230 Touchpad Robotics & Artificial Intelligence-X

