SANKALP STUDY SUCCESS
Way to Learn and Key to Success
PYTHON MODULES CODING PROGRAMS
1. : What is a module in Python? Give an example.
A:
A module is like a code library that contains functions, variables, or classes.
# [Link]
def greeting(name):
print("Hello,", name)
2. : How do you import a module and use a function from it?
A:
import mymodule
[Link]("Sankalp")
3. : How do you store variables inside a module?
A:
# [Link]
person1 = {"name": "John", "age": 36, "country": "Norway"}
4. : How do you access a variable from a module?
A:
import mymodule
print(mymodule.person1["age"])
5. : How do you give an alias name to a module?
A:
import mymodule as mx
print(mx.person1["name"])
6. : How do you import a built-in module in Python?
A:
import platform
print([Link]())
7. : How do you list all functions and variables inside a module?
A:
import platform
print(dir(platform))
8. : How do you import only a specific object from a module?
A:
from mymodule import person1
print(person1["country"])
9. : What is the difference between import module and from module import?
A:
import module → imports the whole module.
from module import → imports only specific items.
10. : How do you check the type of an imported object?
A:
import platform
print(type([Link]()))
11. : How do you check the location of a module file?
A:
import mymodule
print(mymodule.__file__)
12. : How do you import multiple built-in modules at once?
A:
import math, platform
print([Link](16))
print([Link]())
13. : How do you check available built-in modules in Python?
A:
help("modules")
14. : How do you use alias for a built-in module?
A:
import math as m
print([Link])
15. : How do you import everything from a module at once?
A:
from math import *
print(srt(25))
print(pi)