0% found this document useful (0 votes)
3 views

Week4_01_ Introdcution to Google Colab

Google Colab is a free cloud-based Jupyter notebook environment that allows users to write and execute Python code, collaborate in real-time, and utilize popular machine learning libraries. It supports various functionalities such as importing datasets, saving notebooks to Google Drive, and integrating with GitHub. The document also provides an introduction to Python programming, including its syntax, variable declaration, data types, and operators.

Uploaded by

aya
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Week4_01_ Introdcution to Google Colab

Google Colab is a free cloud-based Jupyter notebook environment that allows users to write and execute Python code, collaborate in real-time, and utilize popular machine learning libraries. It supports various functionalities such as importing datasets, saving notebooks to Google Drive, and integrating with GitHub. The document also provides an introduction to Python programming, including its syntax, variable declaration, data types, and operators.

Uploaded by

aya
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 36

Introduction to

Google Colab
Lab 0
What is Google Colab?

Colab is a free Jupyter notebook environment that runs entirely in the


cloud. Most importantly, it does not require a setup and the notebooks
that you create can be simultaneously edited by your team members.
Colab supports many popular machine learning libraries which can be
easily loaded in your notebook.
What Google Colab Offers You?

As a programmer, you can perform the following using Google 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
What is Python?

Python is a popular programming language. It was created by Guido


van Rossum, and released in 1991.

It is used for:
• web development (server-side),
• software development,
• mathematics,
• system scripting.
What is Python?

• Python works on different platforms (Windows, Mac, Linux,


Raspberry Pi, etc).
• 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.
• Python runs on an interpreter system, meaning that code can be
executed as soon as it is written. This means that prototyping can be
very quick.
• Python can be treated in a procedural way, an object-oriented way or
a functional way.
Steps for running a code in Google Colab

Step 1 − Open the following URL in your browser − https://colab.research.google.com


Step 2 − Click on the Sign in button at the top right of the screen to create an account.
Use your google account to create the account.
After signing in to Colab, It will give different options for creating a new notebook.

Step 3 − Create a Notebook by clicking on ( + New notebook)


Another way of creating a notebook.
Let’s give a name for the notebook.
There are two option in the main page to write either code or text:
• Text is for the information or the description of the code. It is only for display.
• Code is where you write your code.
You can generate a code using AI in Colab by describing your program.
You can generate a code using AI in Colab by describing your program.

Output
You can delete a code cell by clicking on the cell then choose delete.
Now add a code and let’s start writing our program.
To see the results, you need to click on the triangle on the right side of each
single code cell.

Output
To see the results of all the cells at the same time, you need to use Run All
instruction .
Exercise

Now try to print the following information:

• Your first name


• Your family name
• Your major
Python Syntax compared 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.
Python Indentation
Indentation refers to the spaces at the beginning of a code line.

Indentation levels of python


Python Indentation

Consistency:
It’s important to be consistent with indentation throughout the
codebase. All statements within the same block must be indented at the
same level.
Spaces or Tabs:
Mixing tabs and spaces for indentation is discouraged as it can lead to
syntax errors.However, it’s recommended to use spaces for better
consistency, as tabs may be interpreted differently in different
environments.
Example of wrong indentation
Python Variables

 Variables: Variables are containers for storing data values.

 Creating Variables
• Python has no command for declaring a variable.
• A variable is created the moment you first assign a value
to it.
Example of declaring variable

Y is: Hi
X is : 5
Can we use the same variable name more than one time ?

What will be the output of


running this code?
4 or Hi ??

Output
Is the variable name case-sensitive? Yes

What will be the output of running this code?

Output
Printing multiple variables

In the print() function, you output multiple variables, separated by a


comma:

Output
Assigning one Value to Multiple Variables

Output
Setting the Data Type

Example Data Type


x = "Hello World" str
x = 20 int
x = 20.5 float
x = ["apple", "banana", "cherry"] list
x = ("apple", "banana", "cherry") tuple
x = range(6) range
x = {"name" : "John", "age" : 36} dict

x = {"apple", "banana", "cherry"} set


Get the Type of the variable

You can get the data type of a variable with the type() function.

Output
Python Operators

Operators are used to perform operations on variables and values.

Operator Name Example


+ Addition x+y
- Subtraction x-y
* Multiplication x * y
/ Division x/y
Python Comparison Operators

Operator Name Example


== Equal x == y
!= Not equal x != y
> Greater than x>y
< Less than x<y
>= Greater than or x >= y
equal to
<= Less than or equal x <= y
to
Adding Comments in python use #

Comment

To comment multiple lines using ’’’

Comment
Let’s try to practice some math in python!
Exercise

Let’s print your age by subtracting your birthdate year from 2024!

The output should be similar to this format:


 For example: My age is 25
By default, notebooks have a maximum lifespan of 12 hours.
Therefore, it's advisable to save your work before closing Colab.
You can save the notebooks to your Google Drive or local storage.

You might also like