Python Modules
Last updated
import datetime
# Get the current date and time
now = datetime.datetime.now()
print(f"Current date and time: {now}")
# Get just the current time
current_time = now.time()
print(f"Current time: {current_time}")import os
# Get the current working directory
cwd = os.getcwd()
print(f"Current working directory: {cwd}")
# List all files and directories in the current directory
print("Files and directories:", os.listdir(cwd))import random
# Generate a random number between 1 and 10
random_number = random.randint(1, 10)
print(f"Random number between 1 and 10: {random_number}")
# Randomly select an item from a list
my_list = ['apple', 'banana', 'cherry']
random_item = random.choice(my_list)
print(f"Random item from list: {random_item}")