Python Crash Course
)}

Data Type Methods

Previously we looked at built in functions such as:

  • len()
  • type()
  • print()

Now, how is a method different from a function?

  • 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.‍ The upper method takes the string movie_title and converts it into upper case letters.

Another built-in method for string data types is the lower method.

‍movie_title = "Harry Potter and the Prisoner of Azkaban" print(movie_title.lower())

‍>> harry potter and the prisoner of azkaban

H‍ere is a list of built in methods in Python that you can use on strings: https://www.w3schools.com/python/python_ref_string.asp

Feedback Summary
4.8
8 students
5

75%
4

25%
3

0%
2

0%
1

0%
Written Reviews
There are no written reviews yet.