0% found this document useful (0 votes)
6 views32 pages

Chapter 1 - Introduction To Python

The document provides an introduction to Python, highlighting its features, installation processes for different operating systems, and tools like Jupyter Notebook and Colaboratory. It also explains the differences between runtime and compile time, as well as interpreter and compiler. Additionally, it covers the concept of virtual environments and includes a simple example of a Python program.

Uploaded by

bigbellfood
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views32 pages

Chapter 1 - Introduction To Python

The document provides an introduction to Python, highlighting its features, installation processes for different operating systems, and tools like Jupyter Notebook and Colaboratory. It also explains the differences between runtime and compile time, as well as interpreter and compiler. Additionally, it covers the concept of virtual environments and includes a simple example of a Python program.

Uploaded by

bigbellfood
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Introduction to

Python
ABOUT ME “Computer engineering graduate (2019)”

● Currently,
○ ML engineer at Fusemachines Nepal.
○ Director at Eca Academy Nepal

● Previously,
○ NLP Engineer @ EKbana Solutions p.t.e
○ Deep Learning Research @ NAAMII
○ Automation Intern @ LOGPOINT

fuse | machines
Python

● created by Guido van Rossum, and released in 1991

● Programming Language is a form of communication, that is used to instruct computer to


perform some specific things. Example: Addition of two numbers.

● Python is a high level, interpreter based programming language which can be used in multiple
field like Web Development, Artificial Intelligence, Networking, etc.

[Link]
Features of Python

1. Free and Open Source

2. Easy to Read and Code

3. Object-Oriented and Procedure-Oriented Language

4. Dynamically Typed Language

5. Easy to Debug

6. Large Standard Library

7. Interpreted Language and many more …


Runtime Vs Compile time

● Runtime is the time at which the ● Compile time is the time at which source
executable code is started running code is converted to executable code

● Runtime errors can be: ● Compile time errors can be:


○ Division by zero ○ Syntax errors
○ Square root of negative numbers, ○ Semantic errors
etc
Interpreter Vs Compiler
Tools that are used to convert source code to (user program) to machine code (assembly program)
that computers can understand and process.

● Interpreter is a program that converts ● Compiler is a program that converts source


source code to machine code line by line code to machine code in one go and
when program is executed. generate executable file that can be run
directly by the computer
● At each execution, interpreter convert
each line of user program to machine ● Compiler generates executable file, so it is
code, the process is slower. faster to run compiled code than interpreted
code.
● Example: Python, Ruby, etc
● Example: C, C++, Java etc
COMPANIES
Download Python Installer

● Goto: [Link]

● Download Stable Python 3.x.x installer appropriate to your system (64 bit or 32
bit)

○ Organizations are shifting their codebase from python 2 to python 3

○ However, Learning python 3, we will also know and able to learn python 2
syntax.
Python Installation on Windows
● Navigate to directory (Downloads) where the python installer is downloaded

○ DOUBLE CLICK to run python installer.

● In the Pop up window, Select Add [Link] to PATH checkbox as in below image. This allows
us to launch python from command line.
Python Installation on Windows (CONTD…)
● If you want to install some advanced features (Recommended), Click customize installation.
Python Installation on Windows (CONTD…)
● Check all of the box available as shown below and click Next.
Python Installation on Windows (CONTD…)
● In advanced options sections, check 2nd, 3rd, 4th checkbox as shown below and Click Install
Python Installation on Windows (CONTD…)
● After Installation Completes, Setup was successful message displays as shown:
Verify Python Installation on Windows

● Goto Start

● Open Command Prompt (cmd)

● Type python and get output as shown:


Python Installation on Linux

● Note: Linux Distribution already has python version installed.

● Installation Steps:
○ Open your terminal (Ctrl + Alt + T)
○ Update your local system’s repository
■ sudo apt update
○ Download the latest version of python3
■ sudo apt install python3
○ apt will find packages, and install python in your system
○ Verify Installation, Type python3 in terminal and get output as below:
Download IDE

● IDE stands for Integrated Development Environment

● A software application that helps programmers develop software code efficiently.

● IDE consists of:


○ Source code editor,
○ Debugger,
○ Build automation tools

● Examples: VScode, Pycharm, Eclipse etc

● Installation VScode
○ Visit [Link]
○ Download and Install for your favourite Operating System
○ Open and Run VScode
Python Pip
● PIP is package manager for Python packages, or modules.

● Uses:
○ Download a package → pip install <package-name>
○ List Downloaded package → pip list / pip freeze
○ Remove a package → pip uninstall <package-name>

● Verify Installation:
○ pip - -version Python package is like a directory that
holds sub-packages and modules.
● Note:
○ Installing python 3.4 or later includes PIP by default

A python module is a file containing python


code
Jupyter Notebook
● The name Jupyter is derived from Julia, Python, and R.

● Jupyter Notebook is one of the most popular tools to create and share documents that
contain interactive code, visualizations, text, etc as a web applications.

● Features:
○ Interactive Environments:
■ Provides interactive computing environments to write and execute code in
individual cells.
○ Rich Output:
■ Can display various types of outputs such as code, table, plots, images, etc
within notebook
○ Documentation and Collaboration:
■ Supports, markdown, a markup language for creating rich-text documents.
■ Notebooks can be shared with others, enabling collaboration as well.
○ Code Execution in any order:
■ Can execute code cells in any order, rather than in sequence from top to bottom.
Installation Jupyter Notebook
● Jupyter Notebook
○ pip install notebook
○ jupyter notebook
“Jupyter Lab is advanced version of Jupyter Notebook
● Jupyter Lab with cool features”
○ pip install jupyter lab
○ jupyter lab

● Notebook via Terminal


○ pip install ipython
○ ipython
Introduction to Colaboratory
● According to documentation, Colab or Colaboratory allows you to write and execute Python in
your browser.

● Features:
○ Zero configuration required
○ Access to GPUs free of charge
○ Easy sharing
Setup Colaboratory

1. Visit: Google Colab 2. Sign in with your credentials

3. Output after sign in successful


What is Virtual Environment?
● Virtual environments in python are isolated environments that allow you to create separate
Python Installations and package installations for different projects.

● Structure of Virtual environments:


1. Directory: Usually created within a directory, which serves as the root of the
environment.

2. Python Interpreter: Within virtual environment directory, there is a separated python


interpreter isolated from the global Python Installation.

3. Site Packages: Each virtual environment has its own site-packages directly. When you
install package using pip or other package managers, they are stored in this directory.

4. Activate script: To work with virtual environment, you need to activate, which can be
done by executing an activate script.

5. Deactivate script: Once you are done working with virtual environment, you can
execute deactivate script specific to the virtual environments
Setup Virtual Environments
● Linux:
○ python3 -m venv <name>

● Windows:
○ python -m venv <name>
○ e.g. python -m venv my_env

● Other Alternatives:
○ Install virtualenv package: pip install virtualenv
○ Cmd: virtualenv <name>

● Activate virtual environments


○ source <venv directory>/bin/activate

● Deactivate virtual environments


○ deactivate
First Python Program
● A python program is a set of instruction that a computer uses to perform a specific task.

○ Display Hello World in your computer screen

print("Hello Word!!!") Print Statement

● A python statement is a instructions that a python interpreter can execute.

○ print("Hello Word!!!") is print statement


Class Work
Q. Write a python program to draw a triangle shape using print statement only.
Python as a Calculator
Python as a Calculator

“Interactive Mode”
Interactive Mode Vs Script Mode

● Interactive model is the way of ● In script mode, python program is


executing a Python program in written in a file. Python interpreter
which statements are written in reads the file, execute, display
command prompt and display result.
result in the same.
● It is more suitable for writing long
● It is suitable for writing very short programs.
programs.
● Debugging is easier
● Debugging is tedious task
● Entire program is compiled and
● Result is obtained after execution of then executed.
each line of code.
Python as a Calculator (Script Mode)
References
● [Link]
● [Link]
● [Link]
n-python-programming/
● [Link]
● [Link]
● [Link]
● [Link]

You might also like