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 - Python Tutorial
From the course: Python for Health Sciences and Healthcare
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
-
(Locked)
Length and count function2m 17s
-
(Locked)
Minimum and maximum function1m 7s
-
(Locked)
Range and sum function3m 8s
-
(Locked)
String case functions1m 37s
-
(Locked)
Split and join function1m 37s
-
(Locked)
Strip and replace function1m 48s
-
(Locked)
Zip function36s
-
(Locked)
Map function1m 31s
-
(Locked)
Slicing1m 25s
-
(Locked)
String formatting1m 19s
-
(Locked)
Solution: Return maximum value from a tuple22s
-
(Locked)
Solution: Print elements in a list in lowercase24s
-
(Locked)
Solution: Zip two lists17s
-
(Locked)
Solution: Get list element using negative indexing33s
-
(Locked)
-
-
-