From the course: Python for Health Sciences and Healthcare

Unlock this course with a free trial

Join today to access over 25,600 courses taught by industry experts.

Length and count function

Length and count function

- [Instructor] Before you write a new function for your function, it's good practice to check if it exists already. Some of the basic things you want to do are already built-in functions and it's intuitive that you can even guess them sometimes. In this chapter, we'll cover built-in functions and other operations in Python. Let's start by looking at the length and count built-in function. You can check the length of a string using the length function. For omeprazole, it returns 10, which is the number of individual characters. You can check the length of a list too. This returns three, which is the number of items in the list. An then the string is a character, so you can check the length too. To count the number of occurrences of a specific item in a sequence, we have the count function. To test this, let's create the list called names_of_ppi containing three medications belonging to the proton pump inhibitor…

Contents