Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
4. Integer placeholders
Date and time
Padding and Alignment


Good job! Empty placeholders {} are good for any type of variable, but they do not provide any additional possibilities. Let's now move on to formatting numbers. We'll start with simple integers:

user_age = 25
print('You are {:d} years old.'.format(user_age))

Result: You are 25 years old.

The {:d} placeholder indicates that we simply want to print an integer value. In this case, we would get the same result with an empty pair of brackets {}. Note that the variable must be of a numerical type—e.g., if the variable you pass in to the formatter is a string, it will throw an exception.


Let's start with something very simple. Ask the user for the current year:

What year is it now?

Next, print the following:

It is year {year} now.