PieceOfAPie
PieceOfAPie
  • Home
  • Tutorials
  • More
    • Home
    • Tutorials
  • Home
  • Tutorials

Modules

Previous Lesson


A module is a file that contains a set of code to accomplish a certain task. Some modules are built in Python modules like math, time, and random. You can also make your own modules! Here are some built in Python modules:

  • Math
  • Time
  • Random
  • Pygame
  • Tkinter
  • CSV
  • OS
  • Logging


To create and access a module, follow these steps:

  1. Create a set of code like this:  Source Code
  2. Now, save that code into a file like module.py
  3. Now, in your main python file, on the top of your program, write import followed by the name of the file without the .py
  4. Now, you can use the module functions like this:  Using Module
  5. To access an in-built python module, just import the module and use its functions like this:  Accessing In-Built Module

Next Lesson

Tuples, Sets, and Dictionaries

Copyright © 2024 PieceOfAPie - All Rights Reserved.

Powered by GoDaddy

This website uses cookies.

We use cookies to analyze website traffic and optimize your website experience. By accepting our use of cookies, your data will be aggregated with all other user data.

Accept