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.