Data Type Methods
Previously we looked at built in functions such as:
Now, how is a method different from a function?
- A functionis a piece of code that is called by name. It can be passed data to operate on, known as arguments, and can optionally return a result.
- A method is a function that is called by a name that is associated with an object. Here is an example of a built-in method that is associated with strings.
movie_title = "Harry Potter and the Prisoner of Azkaban" print(movie_title.upper())
>> HARRY POTTER AND THE PRISONER OF AZKABAN
The data type string has a built in method that can be accessed with the dot notation called
upper method takes the string
movie_title and converts it into upper case letters.
Another built-in method for string data types is the
movie_title = "Harry Potter and the Prisoner of Azkaban" print(movie_title.lower())
>> harry potter and the prisoner of azkaban
Here is a list of built in methods in Python that you can use on strings: https://www.w3schools.com/python/python_ref_string.asp