The print() function is a built-in Python function that allows you to display data of any type. In this video, learn how to use the print() function to display your data.
- [Instructor] There are several, fundamental built in functions in Python that come in handy when working with data. One such function is print. The print function takes in data as input and displays that data on the screen. To illustrate how the print function is used, I'll be walking through some examples. First, let's say that I have a variable named greeting containing this string, Hi, nice to meet you. To display greeting on the screen, I would call the print function and pass and greeting as input like this. Next, say that I have a variable named greeting1 containing the string hey, a variable named name1 containing the string Christine, a variable named greeting2 containing the string hello, a variable named, name2 containing the string lav, and a variable named punctuation containing an exclamation mark as a string. To form sentences using these variables and display them on the screen, I would call the print function and pass in these variables as inputs like this. Then say that I have a variable named odd_nums containing a list of some odd integers. To display odd_nums on the screen, I would call the print function and pass in odd_nums as input like this. Now say that I have a tuple containing variables X1 and Y1, and this tuple will represent the point 5, 6 on a line. And I have another tuple containing variables X2 and Y2 and this tuple represents the point -7, -8 on the same line. To compute the slope of the line using the two points and display the slope with a label on the screen, I would call the print function and passing the string slope, colon, and an arithmetic expression involving the two points has inputs like this. Next, say that I have a data set containing information about students' grades across five exams. And I have a variable named grades_atleast_70 containing a subset of that data set with students grades that are at least 70%. And I have another variable named grades_below_70 containing a subset of the grades dataset, but students grades that are below 70%. To display these two variables with labels, I would call the print function and pass in labels and the variables as inputs like this. There, as you can see, the print function is fundamental to programming and working with data.