Just don’t make it angry
07 November 2022
I made a robot that can see using sound. #shorts
03 November 2022
Best night of his life
12 October 2022
What happens when robots die?
11 October 2022
Pomodoro robot! This is a work in progress but too cute not to share
30 September 2022
Build your own web server using a Raspberry Pi Pico W using Phew.
28 August 2022
Yukon & Omnibot 3000
Omnibot 3000
Pico W Toothbrush
Whats new in Python 3.13a
Maker Faire Rome 2023
WeatherBot
Data Manipulation with Pandas and Numpy
Computer Vision on Raspberry Pi with CVZone
Learn how to program SMARS with Arduino
Build a SMARS Robot in Fusion 360
Python for beginners
Create Databases with Python and SQLite3
KevsRobots Learning Platform
35% Percent Complete
By Kevin McAleer, 3 Minutes
Python is known for its rich set of libraries and modules which simplifies the coding experience. In this lesson, we will understand what Python libraries and modules are, how to import them, and get a brief look at a few popular libraries.
libraries
modules
math
random
datetime
In Python, a module is a file containing Python code. A library is a collection of modules. They define functions, classes, and variables that you can reuse in your programs.
module
file
library
functions
classes
variables
You can use the import keyword to import a module or a library. Once imported, you can use the dot notation to access the functions, classes, and variables defined in that module.
import
# Importing the math module import math # Using a function from the math module print(math.sqrt(16)) # Prints '4.0'
The math module provides mathematical functions and constants.
import math # Constants print(math.pi) # Prints '3.141592653589793' # Trigonometric functions print(math.sin(math.pi/2)) # Prints '1.0' # Logarithmic functions print(math.log(100, 10)) # Prints '2.0'
The random module provides functions for generating random numbers.
import random # Generate a random float between 0 and 1 print(random.random()) # Generate a random integer between 1 and 10 print(random.randint(1, 10)) # Randomly choose an item from a list print(random.choice(['apple', 'banana', 'cherry']))
The datetime module provides classes for manipulating dates and times.
import datetime # Get the current date and time now = datetime.datetime.now() print(now) # Create a specific date independence_day = datetime.datetime(1776, 7, 4) print(independence_day) # Calculate the difference between two dates delta = now - independence_day print(delta.days)
In this lesson, you’ve learned about Python libraries and modules. You’ve learned how to import them and explored a few popular libraries: math, random, and datetime. Libraries and modules are powerful tools that allow you to leverage existing code and build complex applications more easily.
< Previous Next >