We previously used a few functions like
print()
and
len()
where we place the variable inside the parentheses such as
len(my_str)
. On the other hand, a method is a function that is attached to a specific Python object. To access this function, we write the object, then a dot
.
, and then the name of the method. The "dot notation" is the way we connect the name of an object to the name of a method it can perform. For example, we can write
my_str.upper()
when we want the string
my_str
to perform the
upper()
method to create an upper-case version of itself.
Remember that strings are
immutable. Therefore, all string methods give us a new string and must be assigned to a new variable. The original string is unchanged.