from module import function Statement
"from module import function" Statement का उपयोग Python Module से Specific Function Import करने के लिए किया जाता है।
उदाहरण
यदि आप math Library से sin Function Import करना चाहते हैं बिना किसी अन्य Function को Import किए, तो आप इसे निम्न प्रकार से कर सकते हैं:
>>> from math import sin >>> sin(0) 0.0
ध्यान दें कि आपको sin को "math." से Prefix नहीं करना पड़ता क्योंकि केवल sin Import किया गया है, math नहीं।
Imported Functions को Alias करना
आप Imported Functions को Alias भी कर सकते हैं:
>>> from math import cos as cosine >>> cosine(0) 1.0
Multiple Functions Import करना:
from math import sin, cos, tan, pi, sqrt
# या Multiple Lines में
from math import (
sin, cos, tan,
pi, e, sqrt,
log, log10
)
Benefits of Specific Imports:
- Namespace Clean रहता है
- Code Self-Documenting होता है (दिखता है कि क्या Use हो रहा है)
- IDE Autocomplete बेहतर काम करता है
- Static Analysis Tools (pylint, mypy) बेहतर काम करते हैं
- Performance में थोड़ा सुधार