Editor settings

General settings

Save settings

Learn to program with Python

What are methods #

In this lesson, we will briefly discuss methods and will not yet talk about how to create methods. Instead, we will explain the concept in the object-oriented programming section.

A method is a function defined and can be called on different types of objects. For example, in the string data type or string object, there are methods that we mentioned earlier such as str.upper() and str.lower(). Upper and lower are methods of the string objects, and calling the same method on different objects will result in different outcomes. For example,

print("abc".upper()) # ABC
print("def".upper()) # DEF

We can see that even though we call the method or function with the same name, upper(), the outcomes differ depending on the object that the method is called on.

There are many methods in the built-in types that come with the Python language that we cannot explain in full detail in this lesson. We can read the details of each method and its operation in the Python language documentation.

Moving forward in the course, we will distinguish between calling functions and methods to avoid any confusion.

Tests #

  • Call the method title() on the string object so that sentence is equal to "Python Is An Amazing Programming Language!"
Output will be displayed here