0% found this document useful (0 votes)
2 views10 pages

String Methods

The document outlines various string methods in Python, including isupper(), islower(), swapcase(), strip(), find(), and replace(). Each method is explained with examples demonstrating its functionality, such as checking letter case, removing whitespace, and replacing substrings. A summary table is provided at the end, listing the commands and their purposes.

Uploaded by

8s6m5d9ky2
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 views10 pages

String Methods

The document outlines various string methods in Python, including isupper(), islower(), swapcase(), strip(), find(), and replace(). Each method is explained with examples demonstrating its functionality, such as checking letter case, removing whitespace, and replacing substrings. A summary table is provided at the end, listing the commands and their purposes.

Uploaded by

8s6m5d9ky2
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

Strings

String Methods (2)


More string methods first_string = "HELLO"
print(first_string.isupper())

The isupper() method returns


True if a string is all uppercase letters
and False otherwise.

True
More string methods first_string = "HELLO"
print(first_string.islower())

The islower() method returns


True if a string is all lowercase
letters and False otherwise.

False
More string methods first_string = "PyThOn"
second_string = first_string.swapcase()

print(second_string)
The swapcase() method returns
a string in which each letter is the
opposite case as the original string.

pYtHoN
Command What does it
do?

[Link]( ) Switches the


case of letters
(upper becomes
lower and vice
versa)
More string methods first_string = " hi there "
second_string = first_string.strip()

print(second_string)
The strip() method returns a
copy of the string you call it on,
without any whitespace at the
beginning or end.
hi there
More string methods when you call the find method,
you call it on a string, and you
The find()method doesn't also pass it a string as an
return a string. argument.

it can be used to find an It looks in the string you call it


instance of one string on for the first instance of the
inside another string. argument string.

Command What does it do?

[Link]() Finds the first index


value of the
element
More String Methods
my_string = "eggplant" 3

index = my_string.find("plant")
print(index)

In this example, it'll look in my_string for the first instance of "plant".

It returns the index at which the argument string starts.

Here, "plant" starts at index 3 in "eggplant", so the find method returns 3.


More string methods s = “hello everyone”
p = [Link](“hello”, “hi”)

print(p)
The replace() method is
used to create a new
string where a specified
substring is replaced with
another substring.
hi everyone

Command What does it


do?

[Link] ( ) Replaces
specified
substring with
another
substring.
Commands learned this lesson
Command What does it do?

[Link]() Switches the case of letters (upper becomes lower


and vice versa)
[Link]() Finds the first index value of the element

[Link] () Replaces specified substring with another substring.

You might also like