find the current year in python

To find the current year in Python, you can use the datetime module which contains the date class. You can create an instance of the date class using the today() method, which returns the current date. Then, you can simply retrieve the year using the year attribute.

Here's the code to find the current year:

main.py
from datetime import date

current_year = date.today().year
print(current_year)
80 chars
5 lines

This will output the current year in the format YYYY (e.g. 2021).

gistlibby LogSnag