Import statement takes two forms, one is import <module> and second is from <module> import <object>. Why is it possible to use the objects of the imported module without dot notation in second form and not in first one.



When the import <module> statement is used, a new namespace is created for the imported module's objects, so we must use the dot operator to refer to any imported module object. While in the second case, from <module>  import <object> , no new namespace is created , rather the imported objects are added to  the existing namespace so these can be referred without using dot notation.

Go Ad-free
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 14 years. He provides courses for Maths, Science, Social Science, Physics, Chemistry, Computer Science at Teachoo.