prev
next
Or press ESC to close.
To continue enjoying our content, please consider disabling your ad blocker. Your support helps us continue providing quality content. To continue enjoying our content, please consider disabling your ad blocker. Your support helps us continue providing quality content.

Python Programming Part 13

Rajjit Nov 01st, 2023 10 mins read
part-13

TOPIC: Python Modules and Uses

Modules
A module in Python is a file that contains code to perform a specific task or provide some functionality. A module can have variables, functions, classes, and other objects that can be imported and used in other Python programs. Modules help to organize the code and make it more readable and reusable.
There are two types of modules in Python: built-in modules and user-defined modules. Built-in modules are those that come with the Python standard library and provide common and useful features. For example, the math module provides mathematical functions and constants, the os module provides operating system functions, the random module provides random number generation, and so on. User-defined modules are those that are created by the programmers themselves for their own purposes. For example, one can create a module named hello.py that contains a function to greet someone.
To use a module in Python, one has to import it using the import keyword. For example, to import the math module, one can write:

import math

And, for an example of user-defined module, we create a file called file.py and define a function in it. The name of the function, say, greet() can be called in another python file, say app.py. To do that we write

from file import greet
The full explanation of this implementation can be seen in the YouTube Video.

Some uses of Modules of Python are:
  • Performing mathematical operations, such as calculating trigonometric functions, logarithms, factorials, etc. using the math module.
  • Generating random numbers, choices, samples, shuffles, etc. using the random module.
  • Working with dates and times, such as getting the current date and time, formatting and parsing dates and times, performing arithmetic operations on dates and times, etc. using the datetime module.
  • Handling files and directories, such as creating, deleting, renaming, copying, moving, etc. files and directories using the os module.
  • Processing text, such as splitting, joining, replacing, searching, matching, etc. strings using the string module or regular expressions using the re module.
  • Parsing and manipulating data formats, such as JSON, XML, CSV, etc. using the json module, the xml module, the csv module, etc.
  • Sending and receiving data over the internet, such as making HTTP requests, downloading web pages, scraping web data, etc. using the requests module or the urllib module.
  • Creating graphical user interfaces (GUIs), such as creating windows, buttons, menus, dialogs, etc. using the tkinter module or other GUI frameworks.
  • Developing web applications or web services using web frameworks such as Flask or Django.
  • Performing data analysis or machine learning using libraries such as NumPy, pandas, scikit-learn, TensorFlow, etc.
  • To find out more about the Python Modules in Packages, visit the link
    👉🏻 Python Modules Documentation
  • 👉🏻 Python Turtle Graphics Documentation

Code as discussed in the video:

# Python Modules - uses

'''Definition: A python file that contains some function definitions and statements '''
# from tut11 import factorial
# output = factorial(5)
# print("the factorial is", output)

# import random

# random_num = random.randint(10, 50)
# print(random_num)

# import calendar
# print(calendar.month(2025, 12))

from turtle import*
while True:
    forward(100)
    left(100)

You can copy and run this code