It is recommended to not to use import *
in Python.
Can anyone please share the reason for that, so that I can avoid it doing next time?
It is recommended to not to use import *
in Python.
Can anyone please share the reason for that, so that I can avoid it doing next time?
You’re absolutely right to question the use of import *
— it’s generally discouraged in Python for several important reasons:
import *
from math import *
from statistics import *
# Which sqrt() are you calling now?
print(sqrt(9))
sqrt()
, it’s unclear if it’s from math
, numpy
, or somewhere else.import *
can lead to subtle circular dependencies.from math import sqrt, pi
import math
math.sqrt(16)
This makes your code clearer, safer, and easier to debug or scale.