0% found this document useful (0 votes)
2 views

class 9 string

Uploaded by

shivangiupa123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

class 9 string

Uploaded by

shivangiupa123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

METHOD IN STRING

Example The strip() method removes any whitespace


from the beginning or the end:
a = " Hello, World! "
print(a.strip()) # returns "Hello, World!"
print(a.lstrip()) # returns "Hello, World! "
Removes any whitespace from the beginning.
print(a.rstrip()) # returns " Hello, World!"
Removes any whitespace from the end
Example The len() method returns the length
of a string:
a = "Hello, World!"
print(len(a)) # returns 13
Example The lower() method returns the
string in lower case:
a = "Hello, World!"
print(a.lower())# returns "hello, world!"
Example The upper() method returns the
string in upper case:
a = "Hello, World!"
print(a.upper())# returns "HELLO, WORLD!"
Example The title() Converts the first
character of each word to upper case:
a = "hello, world!"
print(a.title())# returns "Hello, World!
Example The count() Returns the number of
times a specified value occurs in a string:
a = "hello, world!"
print(a.count("l")) # returns 3
Example The find() Searches the string for a
specified value and returns the position of
where it was found:
a = "Hello, World!"
print(a.find("l")) # returns 2
print(a.find("l",4)) # returns 10
Example The replace() method replaces a
string with another string:
a = "Hello, World!"
print(a.replace("H", "J"))#returns "Jello, World!"
Example The split() method splits the string
into substrings if it finds instances of the
separator:
a = "Hello, World!"
print(a.split(",")) # returns ['Hello', ' World!']
THANK
YOU

You might also like