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

Learn in your speed, with individual attention - Teachoo Maths 1-on-1 Class

Ask a doubt
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

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