21CSS101J-U4-S1-SLO1-Introduction to python and Google colab
21CSS101J-U4-S1-SLO1-Introduction to python and Google colab
3
Introduction to Python (3/8)
Python Language Features
Interpreted
• There are no separate compilation and execution steps like C and C++.
• Python runs on an interpreter system, meaning that code can be
executed as soon as it is written
Platform Independent
• Python programs can be developed and executed on multiple
operating system platforms.
• Python works on different platforms (Windows, Mac, Linux, Raspberry
Pi, etc).
4
Introduction to Python (4/8)
Python Language Features
• Python has a simple syntax similar to the English language.
• Python has syntax that allows developers to write programs with
fewer lines than some other programming languages.
Rich Library Support
• The Python Standard Library is very vast.
• Known as the “batteries included” philosophy of Python ;It
can help do various things involving regular expressions,
documentation generation, unit testing, threading, databases,
web browsers, CGI, email, XML, HTML, WAV files,
cryptography, GUI and many more.
5
Introduction to Python (5/8)
Python syntax in comparison to other programming languages
• Python was designed for readability, and has some similarities to the
English language with influence from mathematics.
• Python uses new lines to complete a command, as opposed to other
programming languages which often use semicolons or parentheses.
• Python relies on indentation, using whitespace, to define scope; such
as the scope of loops, functions and classes. Other programming
languages often use curly-brackets for this purpose.
6
Introduction to Python (6/8)
Python syntax
Python syntax can be executed by writing directly in the Command
Line:
>>> print("Hello, World!")
Hello, World!
Or by creating a python file on the server, using the .py file extension,
and running it in the Command Line:
C:\Users\Your Name>python myfile.py
7
n1=input(‘Enter Number1’)
n2=input(‘Enter Number2’)
if n1>n2:
print(‘n1 is greater’)
else:
print(‘n1 is greater’)
Introduction to Python (7/8)
Python syntax
Python Indentation: Indentation refers to the spaces at the beginning of a code line.
Where in other programming languages the indentation in code is for readability only, the
indentation in Python is very important.
Python uses indentation to indicate a block of code.
Example
if 5 > 2:
print("Five is greater than two!")
Python will give you an error if you skip the indentation:
Example
Syntax Error:
if 5 > 2:
print("Five is greater than two!")
9
Introduction to Python (8/8)
Python Applications
10
Introduction to Google Colab (1/7)
• Google developed AI framework called TensorFlow and a development tool called
Colaboratory. Today TensorFlow is open-sourced and since 2017, Google made
Colaboratory free for public use. Colaboratory is now known as Google Colab or
simply Colab.
• Another attractive feature that Google offers to the developers is the use of GPU.
Colab supports GPU and it is totally free. It may also have a long term perspective of
building a customer base for Google Cloud APIs which are sold per-use basis.
• Irrespective of the reasons, the introduction of Colab has eased the learning and
development of machine learning applications.
11
Introduction to Google Colab (2/7)
• Google Colab is a document that allows you to write, run, and share
Python code within your browser. It is a version of the popular Jupyter
Notebook within the Google suite of tools.
• Jupyter Notebooks (and therefore Google Colab) allow you to create a
document containing executable code along with text, images, HTML,
LaTeX, etc. which is then stored in your google drive and shareable to peers
and colleagues for editing, commenting, and viewing.
12
Introduction to Google Colab (3/7)
What Can You Get From Colab?
• Write and execute code in Python
• Document your code that supports mathematical equations
• Create/Upload/Share notebooks
• Import/Save notebooks from/to Google Drive
• Import/Publish notebooks from GitHub
• Import external datasets e.g. from Kaggle
• Integrate PyTorch, TensorFlow, Keras, OpenCV
• Free Cloud service with free GPU
13
Introduction to Google Colab (4/7)
Starting a document
• As Colab implicitly uses Google Drive for storing your notebooks, ensure that you
15
Introduction to Google Colab (6/7)
Add a new code cell by clicking the “+ Code” button in the top left corner of
the document. Add a text cell by clicking the “+ Text” button in the top left
corner of the document.
When a cell is selected, a toolbar will appear in the top right corner of the
cell. This toolbar contains functions specific to that cell. Options include
moving the cell up and down, adding comments, and deleting the cell.
16
Introduction to Google Colab (7/7)
Sharing a Colab notebook
As with other Google Apps, Colab Notebooks can be shared. Look for
the “share” button in the top right-hand corner of the window. Google
Colab documents can also be shared in Google Drive, just you do with
other types of documents.
17