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,
- Single line comments – Written using # (pound/hash symbol)
- Multi-line comments – Written using ‘’’ Comment ‘’’ or “”” Comment “””.
REPL:
REPL stands for Read Evaluation Print Loop. We 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:
- Write a program to print any poem in python.
- Use REPL and print the table of 5 using it.
- Install an external module and use it to perform an operation of your interest.
- Search online for the function and Write a python program to print the contents of a directory using os module.
- Label the program written in problem 4 with comments.
- Use any 4 build-in modules.
Great
ReplyDelete