wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Datetime_builtinfunctions_pythonquiz

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

What does datetime.datetime.now() return?

a)
  1. Current date and time

b)

Current date only

c)

Current time only

d)

None of the above

2.

Which function gives the day of the month from a datetime object?

a)

.day

b)

.month

c)

.date

d)

.now

3.

import datetime

print(datetime.datetime.now().strftime("%B"))

what will be the output of the following?

a)

Current month in full name (e.g., January)

b)

Current year

c)

Current month in number format

d)

Gives error

4.

What does the strftime method do?

a)

Converts date to a string in a specified format

b)

Extracts the current time

c)

Formats strings only

d)

none of these

5.

from datetime import date

today = date.today()

print(today.strftime("%Y-%m-%d"))

What is the output of this code?

a)
  1. Current date in "YYYY-MM-DD" format

b)

Current time

c)

Error

d)

None of the above

6.

What does random.randint(1, 10) do?

a)

Returns a random number between 1 and 10 (inclusive)

b)

Always returns 10

c)

Returns a random number between 1 and 9 (inclusive)

d)

None of these

7.

Which function generates a random number in the range [0, n)?

a)

random.randrange(n)

b)

random.randint(0, n)

c)

random.random()

d)

random()

8.

import random

print(random.choice("Kidzian"))

What does this code do?

a)
  1. Selects a random letter from "Kidzian"

b)

Shuffles the string

c)

Prints the string "Kidzian"

d)

None of these

9.

# What will be the output of the following code?

import datetime

today = datetime.datetime.now()

print(today.strftime("%A"))

a)

Current weekday as a number

b)

Current weekday as a full name

c)

Current month

d)

Error

10.

In which of these years will February have 29 days?

a)

1900

b)

2000

c)

2023

d)

2025