7. • Connect / Changing Runtime
• Every time you open the colab file, you should connect the server first.
Click!
Getting Started
8. • Connect / Changing Runtime
• If you want to use “GPU”, click on “Runtime” > “Change Runtime Type” and
select “GPU”for “Hardware Accelerator”
Getting Started
9. • Creating a new “cell”
• You can create two kinds of cell, one is “code” by clicking +Code, another is
text cell by clicking +Text.
• There are options you can move your cell up or down or copy or delete it.
Code Cell
Text Cell
Getting Started
10. • You can type python code in code cell, or use “!”to change the code cell to
treating the input as a shell script to install python module or do something.
Python
shell script
shell script
Other magic commands are listed here
Getting Started
11. • Click on the play button to execute a specific cell
• Other options to run the code
Executing Code Block
12. • File Folder
• Click the folder icon on the screen-
left to view your current files.
• If the files are not immediately
shown, click the refresh button.
• Note!!! Files are temporarily stored,
and it will be removed once you end
your session.
Folder icon
refresh
File Manipulation
13. • Upload files
Click the upload icon
to upload local files
● Download files ● Get files current path
Click “ ”
⋮ and download
button to download files
Click “ ”
⋮ and copy path
button to get the path
File Manipulation
14. • Mounting Google Drive
• Click on the Google drive icon and allow the connect message
File Manipulation
15. • Saving Notebook
• Download the .ipynb file to your local device
( File > Download .ipynb)
• Save the colab notebook to your google drive
( File > Save a copy in Drive)
• Convert .ipynb to .py and download file
( File > Download .py)
File Manipulation
16. • If user does not interact with his Google Colab notebook for more than 90
minutes, its instance is automatically terminated.
• GPU usage is not unlimited. (the max gpu usage 12 hrs)
Colab Limit
24. Strings
• Show the output – “print()”
You need to use quotation(“ ”) for strings
You can use + to connect strings
You can use * to repeat strings
25. Python as a calculator
• Just try it! Click play button or try shift+enter
運算子 功能 範例
+ 加 a + b
- 減 a - b
* 乘 a * b
** 指數 a ** b
/ 除 a / b
// 整數除法 a // b
% 取餘數 a % b
26. Assign
• a = b means b (object) has been assigned to a (variable)
運算子 功能 範例
= 指派 a = b
+= 相加同時指派 a += b
-= 相減同時指派 a -= b
*= 相乘同時指派 a *= b
**= 取指數同時指派 a **= b
/= 相除同時指派 a /= b
/= 整數相除同時指派 a //= b
%= 取餘數同時指派 a %= b
You don’t need to use quotation(“ ”) for variable
27. Assign
• How to know a is equal to b ?
You can use double equal to identify
Boolean
Boolean
39. • Container Data Types
You can use [ ] to define list
You can use ( ) to define tuple
You can use { } to define set
You can use { } and call the key to define dict
Variable Type
40. • Another story to explain variable and data types
CUP_A = 30 (整數)
CUP_B = 30.5 (浮點
數)
CUP_C = " 杯子 " (字串)
(Slide Credit : Santy)
Variable Type