Last active
March 2, 2021 13:49
-
-
Save ofelix03/0b564d8027c67ab223d26070db777328 to your computer and use it in GitHub Desktop.
Evaluating the rectangle area using Str.format() and %-formatting
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| rec_width = 5 | |
| rec_length = 10 | |
| rec_area = rec_width * rec_length | |
| # Using Str.format() | |
| print("The area of a rectangle with {rec_length} and {rec_width} is {rec_area}".foramt(rec_length=rec_length, rec_width=rec_width, rec_area=rec_area)) | |
| # Using %-formatting | |
| print("The area of a rectangle with %(rec_length)s and %(rec_length)s is %(rec_area)s" %{'rec_length': rec_length, 'rec_width': rec_width, 'rec_area': rec_area}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment