Skip to main content

Chapter1

CHAPTER 1 – MODULES, COMMENTS & PIP

Let’s write our very first python program. Create a file called hello.py and paste the below code in it.

print("hello world") # print is a function (more later)

Execute this file (.py file) by typing python hello.py and you will see Hello World printed on the screen.

MODULES

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

PIP

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

pip install flask # Installs Flask Module

TYPES OF MODULES

There are two types of modules in Python.

  1. Built in Modules (Preinstalled in Python)
  2. External Modules (Need to install using pip) Some examples of built in modules are os, random etc. Some examples of external modules are tensorflow, flask etc.
USING PYTHON AS A CALCULATOR

We can use python as a calculator by typing “python” + ↵ on the terminal.

This opens REPL or Read Evaluate Print Loop.

COMMENTS

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

execute. This can be used to mark author name, date etc.

TYPES OF COMMENTS

There are two types of comments in python.

1. Single Line Comments: To write a single line comment just add a ‘#’ at the start

of the line.

# This is a Single-Line Comment

2. Multiline Comments: To write multi-line comments you can use ‘#’ at each line

or you can use the multiline string (""" """)

"""This is an amazing
example of a Multiline
comment!""