What are methods #
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.
Tests #
- Call the method
title()on the string object so thatsentenceis equal to"Python Is An Amazing Programming Language!"
Getting Started with Python
Data Types
Python Functions
Statements in Python
Basic Debugging in Python
Basic Algorithm
Object-Oriented Programming
Error Handling
Intermediate Algorithm
Python Modules