0% found this document useful (0 votes)
11 views3 pages

8.python Module

The document provides a comprehensive guide on Python modules, including definitions, examples, and usage instructions. It covers how to import modules, access variables, create aliases, and list functions within modules. Additionally, it explains the differences between importing whole modules and specific items, as well as how to check for built-in modules and their locations.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

8.python Module

The document provides a comprehensive guide on Python modules, including definitions, examples, and usage instructions. It covers how to import modules, access variables, create aliases, and list functions within modules. Additionally, it explains the differences between importing whole modules and specific items, as well as how to check for built-in modules and their locations.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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)

You might also like