2.5.3 Importing and Using Libraries
Python Programming
Libraries are like pre-built toolkits that you can use without having to write all the code yourself. Let's explore how to import and use different libraries with some simple examples.
Example: Import the random library to generate random numbers.
import random
# Generate a random number between 1 and 10
number = random.randint(1, 10)
print("The random number is:", number)Explanation: The random library helps you generate random numbers, which can be useful in games, simulations, or even to pick a winner in a lucky draw.
Example: Import the datetime library to work with dates and times,