Python Practical Assignment 14.1

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

Introduction

In Python, we can use the built-in datetime module to get the current year and display the month 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 using now().
  4. Extract the year.
  5. Use strftime("%b") to get the short month name.
  6. Print the year and month.
  7. End the program.

Source Code (Beginner Friendly)

# Python program to print current year and short month name

import datetime

# Get current date and time
current_date = datetime.datetime.now()

# Extract year
year = current_date.year

# Extract short month name
short_month = current_date.strftime("%b")

# Print result
print("Year:", year)
print("Short Month:", short_month)

Sample Output

Year: 2026
Short Month: Feb

(Output may change based on current date.)


Viva Questions with Answers

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

The datetime module.

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

It returns the short month name.

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

By using datetime.datetime.now().

4. How do we get the year from the current date?

By using the .year attribute.

5. Can we print the full month name?

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