Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save ofelix03/0b564d8027c67ab223d26070db777328 to your computer and use it in GitHub Desktop.

Select an option

Save ofelix03/0b564d8027c67ab223d26070db777328 to your computer and use it in GitHub Desktop.
Evaluating the rectangle area using Str.format() and %-formatting
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