Streamline Your Prints (Exercise)
00:00
In this exercise, you’ll get to streamline your prints. Like you saw before, just concatenating them might get a little clunky. So here you’ve got an exercise where you can try three different types of displaying the same string using different ways of assembling the string: concatenation, str.format()
, and also using an f-string.
00:21
The task is to create a float object named weight
with the value of 0.2
, and then create a string object named animal
with the value "newt"
, and then use these objects to print the following string.
00:32
So first, only using concatenation, the string should say 0.2 kg
is the weight of the newt.
And then you should display the same string using the .format()
method and empty curly bracket placeholders.
00:45 And finally, also do the same thing using an f-string. Okay, I will copy this part of the string
00:55 so I can then use it in the script. Then I don’t have to type it out. I’d probably make typos, and I’d rather avoid that.
01:03 Go ahead and solve that challenge for yourself and then see you in the next lesson.
Become a Member to join the conversation.