Text Workout
- 03:34
Learn how to use the format function in Python to dynamically insert numerical values into a text string.
Downloads
No associated resources to download.
Transcript
Okay, so now you're going to take what you just learned in this text section and put it into practice. Open up your Jupyter Notebook file, and hopefully you've been using it already to follow along with the code in this lesson and print the statement below using the format function. So I want you to print this. Price equals two 20 EPS equals 10 pe equals two 20 divided by 10. I want you to input all of that as text, but then after the text block, insert the 220, the 10, and the 220 divided by 10 using the format function. So separate each of those using the format function, separate them with commas, and then execute it. And what you should see is you'll get price equals 220 EPS equals 10. And then that PE multiple should automatically calculate for you. So make sure that when you insert it into the format function, that 220 over 10, insert them as numerical values, not as text. And when it's inserted into the text as a dynamic value, that will calculate and you'll see it all come together in one printed output. Now, I want to mention how important it is that you're doing these exercises and hopefully also coding along with the lesson studies show that if you're just sitting back and listening to the lesson passively and not actively being involved in your learning, then you're only gonna retain about 15% of what you learn in the long run. And that's really not a good use of your time because I know that you're busy and I know that you have a lot of other things that you can be doing besides investing in learning machine learning. And you know how important this is for your future and more importantly that you're spending time on this. So I want you to use your time effectively by being active when you listen to the lessons, have that Jupyter notebook out and use it as I'm showing you how to code code along with me. And especially when we get to the exercises, always make sure and do them. And even when you get to a challenging one later on in the lessons, make sure and give it a shot first. Give it your best try before you go and look at the solutions, because that's really going to help you learn and retain this information in the long run so that you can use it to make an impact in your career.
In the cell block below, exercise 3.1. Let's write out that code.
Okay, so here is the code that you should have written for exercise 3.1. Now this 220 is gonna flow to price here these curly braces, the 10 is gonna flow to the second curly braces. And since it's the third object in these parentheses, this 22 divided by 10 is gonna move to this third set of curley braces. But because these are numerical values separated by an operator, that operation is going to take place, and this PE multiple is going to be 22. Let's execute that code cell.