python3 module

  • Module is a file consisting of Python code.
  • Module to be the same as a code library.
  • A module can define functions, classes and variables.
  • Module is a file containing Python definitions and statements.
  • Module is deprecated and replaced by the python module.
  • Example

    Python code for a module named in a file namedaname.py. Here is an example of a simple module, support.py −
    def print_func( par ):
       print "Hello : ", par

    Naming a Module

    module file extension is => .py

    import Statement

    The import has the following syntax −

    import module1[, module2[,... moduleN]
    A search path is a list of directories that the interpreter searches before importing a module.
      def greeting(name):
      print("Hello, " + name)

    person1 = {
      "name": "Rajesh",
      "age": 36,
      "country": "India"


    Import only the person1 dictionary from the module:

      from mymodule import person1

    print (person1["age"])

    Output: 36

    Built-in Modules

    There are several built-in modules in Python, which you can import whenever you like.


    Import and use the platform module:

      import platform

    x = platform.system()
    Important note The dir() function can be used on all modules, also the ones you create yourself.

    welookups is optimized for learning.© welookups. 2018 - 2019 All Right Reserved and you agree to have read and accepted our term and condition.