A Library is a collection of functions and methods that can be used to reduce repetitive tasks. These functions are stored in different files to keep your code more organized and readable.
A library that comes pre-installed with Python is the time library. Here's an example of how to use a library:
import time
start_time = time.time() #gets current time
time.sleep(1) #pauses for 1 second
end_time = time.time()
total_time = end_time - start_time
print("Seconds taken:")
print(total_time)
When using a library, you use the library name and the function name with a period in between. To skip this step, you can import only specific functions like this:
from time import sleep
sleep(1)
from time import *
#the * means all functions will be imported
time()
You can change the prefix of your library call by importing the library as variable name: import RoboPiLib as RPL
If you need to import a library from another directory, you can use the relative path of your current file.
import directory/file