Skip to content

Instantly share code, notes, and snippets.

@ItsCrem
Created November 16, 2017 13:27
Show Gist options
  • Select an option

  • Save ItsCrem/c157684fa8fee2ac1eb2e77d57a1f874 to your computer and use it in GitHub Desktop.

Select an option

Save ItsCrem/c157684fa8fee2ac1eb2e77d57a1f874 to your computer and use it in GitHub Desktop.
stringFormattingPractice created by MaxCaminer - https://repl.it/@MaxCaminer/stringFormattingPractice
age = 24
#Old way
print("My age is " + str(age) + " years")
#New way
print("My age is {0} years".format(age))
print("There are {0} day in {1}, {2}, {3}, {4}, {5}, {6} and {7}".format(31, "January", "March", "May", "July", "August", "October", "December"))
for i in range(1,12):
print("No. {0:2} squared is {1:<4} and cubed is {2:<4}".format(i, i ** 2, i ** 3))
print("Pi is approximately {0:12}".format(22/7))
print("Pi is approximately {0:12.5f}".format(22/7))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment