Created
November 16, 2017 13:27
-
-
Save ItsCrem/c157684fa8fee2ac1eb2e77d57a1f874 to your computer and use it in GitHub Desktop.
stringFormattingPractice created by MaxCaminer - https://repl.it/@MaxCaminer/stringFormattingPractice
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
| 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