Check sibling questions

How can we import a module in Python?

 

Answer:

There are 2 ways to import a module in python:

Using import

Syntax:

import <module_name1>[,<module_name2>,.....,<module_namen>]

Example:

import math,random

Using from

Syntax:

from <module_name> import <function1>[,<function2>,…<functionn>] 

Example:

from math import pi

  1. Computer Science - Class 12
  2. Chapter 14 - Functions in python

About the Author

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science and Computer Science at Teachoo