Python Practical Assignment 13.1

Write a Python Program to Print Year & Short Version of Month

Introduction

In Python, we can use the datetime module to get the current year and month. The month can be displayed in short format like Jan, Feb, Mar, etc.


Logic to Write the Code

  1. Start the program.
  2. Import the datetime module.
  3. Get the current date.
  4. Extract the year.
  5. Print the year and short month using strftime("%b").
  6. End the program.

Source Code (Beginner Friendly)

# Python program to print current year and short version of month

import datetime

# Getting current date
today = datetime.datetime.now()

# Extracting year and short month
year = today.year
month = today.strftime("%b")

# Printing result
print("Year:", year)
print("Month (Short):", month)

Sample Output

Year: 2026
Month (Short): Feb

(Output may vary depending on current date.)


Viva Questions with Answers

1. Which module is used to get date and time in Python?

The datetime module.

2. What does %b represent in strftime()?

It represents the short month name.

3. How do you get the current date in Python?

By using datetime.datetime.now().

4. How do you extract the year from the current date?

By using .year attribute.

5. Can we print full month name instead of short?

Yes, by using %B in strftime().


Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top