Modules, Comments & Pip (Session-2)

 Modules:

A module is a file containing code written by somebody else (usually) which can be imported and used in our programs.

Types of Modules:

There are two types of modules in Python:

  • Built-in modules – Pre-installed in Python
  • External modules – Need to install using pip

Pip:


Pip is a package manager for python. You can use pip to install a module on your system.

E.g., pip install flask (It will install flask module in your system).


Comments:

Comments are used to write something which the programmer does not want to execute.

Comments can be used to mark the author's name, date, etc.


Types of Comments:


There are two types of comments in python,

  1. Single line comments – Written using # (pound/hash symbol)
  2. Multi-line comments – Written using ‘’’ Comment ‘’’ or “”” Comment “””.

REPL:

 REPL stands for Read Evaluation Print LoopWe can use python as a calculator by typing “python” + TO DO on the terminal.

Now create a file:

hello.py and paste the below code into it.

print(“Hello World”)       Here Print is a function.

Practice Exercise 1:

  1. Write a program to print any poem in python.
  2. Use REPL and print the table of 5 using it.
  3. Install an external module and use it to perform an operation of your interest.
  4.  Search online for the function and Write a python program to print the contents of a directory using os module.
  5. Label the program written in problem 4 with comments.
  6. Use any 4 build-in modules.

Comments

Post a Comment

Popular posts from this blog

Loops and Functions Session 8

Python Installation

How to Change your (dev/visual) console color