Python Fundamentals

01 - Welcome & Setup

Instructor and Agenda Introduction

Welcome to Python Programming Fundamentals for Researchers! This course is designed specifically for researchers who want to harness the power of Python for data analysis, visualization, and scientific computing. Whether you're working with experimental data, conducting literature reviews, or building computational models, Python will become an invaluable tool in your research toolkit.

My names is Victor Gambarini. I have been working with Python for more than ten years. I got my PhD from The University of Auckland, where I did a lot of bioinformatics and programming. One of my greatest research outputs is an online database of microorganisms tha can biodegrade plastics called PlasticDB. PlasticDB was 100% coded in Python and has been running stable for many years. It mostly uses a Python package called Flask. We will not be covering it here, but you will definitelly have the knowledge to learn Flask after this course!

About This Course

Over the next three days, we'll build your Python skills from the ground up, focusing on practical applications that researchers use daily. You'll learn not just the syntax, but how to think computationally about research problems. Another feature of this course is that it includes a lot of practice. Practicing is very important in programming so we can build what they call muscle memory. We will build lots of muscle memory in this course!

Course Structure

  1. Welcome & Setup - Getting started with Python and Colab
  2. Variables & Data Types - Numbers, strings, booleans, and naming conventions
  3. Working with Strings - String methods, formatting, and research applications
  4. Basic Operations - Arithmetic, comparison, and logical operators
  5. Input/Output & Debugging - User input, print statements, and error messages
  6. Lists Deep Dive - Creating, accessing, and modifying research data collections
  7. Dictionaries & Sets - Key-value relationships and data organization
  8. Conditional Logic - If/elif/else statements and decision-making
  9. Loops & Iteration - For and while loops with research data
  10. Function Fundamentals - Writing reusable code for research workflows
  11. File Operations - Reading and writing text files and CSV data
  12. Error Handling - Understanding errors and defensive programming
  13. Best Practices & Next Steps - Clean code and reproducible research

What You'll Accomplish

By the end of this course, you'll be able to:

  • Write Python scripts to automate repetitive research tasks
  • Import, clean, and analyze datasets
  • Create publication-quality visualizations
  • Share your code and collaborate with colleagues
  • Apply computational thinking to research problems

Prerequisites

No prior programming experience is required! We'll start from the very beginning. All you need is:

  • A computer with internet access
  • A Google account (for Colab)
  • Curiosity and willingness to learn

Why Use Colab

What is Google Colab?

Google Colaboratory (Colab) is a free cloud-based platform that allows you to write and run Python code in your web browser. Think of it as a combination of a word processor and a Python interpreter, all running in the cloud.

Why Colab is Perfect for Researchers

1. No Installation Hassles

  • No need to install Python, libraries, or manage environments
  • Everything runs in your browser
  • Works on any operating system (Windows, Mac, Linux)

2. Free Access to Powerful Computing

  • Free GPU and TPU access for computational tasks
  • Pre-installed scientific libraries (pandas, numpy, matplotlib, etc.)
  • 12+ hours of continuous runtime per session

3. Easy Sharing and Collaboration

  • Share notebooks like Google Docs
  • Real-time collaboration with colleagues
  • Integrated with Google Drive for automatic saving

4. Perfect for Learning

  • Mix text, code, and output in one document
  • Ideal for documenting your research process
  • Great for creating reproducible analyses

5. Research-Friendly Features

  • Built-in data visualization tools
  • Easy file uploads and downloads
  • Integration with Google Drive, GitHub, and other platforms

Colab vs. Other Options

Feature Google Colab Local Python Jupyter Lab
Setup Required None Extensive Moderate
Cost Free Free Free
Collaboration Excellent Poor Good
GPU Access Free Expensive Expensive
Sharing Easy Difficult Moderate

How to Open a New Notebook

Step 1: Navigate to Colab

  1. Open your web browser
  2. Go to colab.research.google.com
  3. Sign in with your Google account

Step 2: Create a New Notebook

  1. Click "New notebook" in the bottom right corner

Create new Colab notebook

  1. Alternatively, use File > New notebook from the menu
  2. Your new notebook will open with a single empty cell

Step 3: Rename Your Notebook

  1. Click on "Untitled0.ipynb" at the top of the page
  2. Enter a descriptive name (e.g., "My First Python Notebook")
  3. The notebook will automatically save to your Google Drive

Text and Code Cells

Understanding Cell Types

Colab notebooks consist of two main types of cells:

Code Cells

  • Purpose: Write and execute Python code
  • Recognition: Gray background with a play button () on the left
  • Execution: Click the play button or press Shift + Enter
  • Output: Results appear directly below the cell

Example Code Cell:

Run code on Colab

Text Cells

  • Purpose: Add explanations, notes, and documentation
  • Recognition: White background, markdown formatting
  • Format: Uses Markdown syntax for formatting
  • Editing: Double-click to edit, Shift + Enter to render

Example Text Cell:

Use markdown on Colab

Creating New Cells

  • Add Code Cell: Click + Code in the toolbar
  • Add Text Cell: Click + Text in the toolbar
  • Keyboard Shortcuts:
  • Ctrl + M, B - Add cell below
  • Ctrl + M, A - Add cell above

Cell Operations

  • Run Cell: Shift + Enter
  • Delete Cell: Select cell, then Ctrl + M, D
  • Copy Cell: Ctrl + C
  • Paste Cell: Ctrl + V
  • Move Cell: Use arrow buttons

Move cell on Colab


Upload Files

We will first download the famous Penguins dataset from our website. Just download it from this link: penguincs.csv. Then we will upload it to Colab:

  1. Click the folder icon () in the left sidebar
  2. Click the upload button ()
  3. Select the penguins.csv file from your computer
  4. The file will appear in the /content/ directory

Upload a file to Colab

Note: Files uploaded this way are temporary and will be deleted when the runtime disconnects.


Save Notebook

Automatic Saving

  • Colab automatically saves your notebook to Google Drive
  • Saves occur every few minutes and after each cell execution
  • Look for the "All changes saved" indicator in the toolbar

Saving the notebook on Colab

Manual Saving

  • Keyboard shortcut: Ctrl + S (Windows/Linux) or Cmd + S (Mac)
  • Menu option: File > Save

Saving Options

1. Save a Copy

  • File > Save a copy in Drive: Creates a duplicate
  • File > Save a copy in GitHub: Saves to your GitHub repository

2. Download Options

  • File > Download > Download .ipynb: Jupyter notebook format
  • File > Download > Download .py: Python script format
  • File > Download > Download .html: Web page format
  • File > Download > Download .pdf: PDF document

Best Practices for Saving

  1. Use descriptive filenames: "Data_Analysis_Project1.ipynb" not "Untitled1.ipynb"
  2. Create copies before major changes: File > Save a copy in Drive
  3. Download backups of important work
  4. Use version control (we'll cover GitHub in Session 11)

Sharing Your Notebook

  1. Click the "Share" button in the top right
  2. Choose sharing permissions:
  3. Restricted: Only you can access
  4. Anyone with the link: Anyone can view
  5. Anyone with the link can edit: Anyone can modify
  6. Copy the link to share with colleagues

Sharing the notebook on Colab

Collaborative Features

  • Real-time editing: Multiple people can edit simultaneously
  • Comments: Add comments to cells for discussion
  • Suggestions: Collaborators can suggest changes
  • Version history: View and restore previous versions

Quick Reference

Essential Keyboard Shortcuts

  • Shift + Enter: Run cell and move to next
  • Ctrl + Enter: Run cell and stay in current cell
  • Ctrl + M, D: Delete cell
  • Ctrl + M, A: Add cell above
  • Ctrl + M, B: Add cell below
  • Ctrl + /: Comment/uncomment code

Getting Help

  • In Colab: Help > Search code snippets
  • For Python functions: Use help(function_name) or ?function_name
  • Documentation: Access built-in help with ??function_name

What's Next?

In our next session, we'll dive into Python basics - variables, data types, and fundamental operations. Make sure you can comfortably create notebooks, add cells, and save your work before we continue.

Enjoying this course?

This is just the first episode! Register to unlock 12 more episodes and complete your learning journey.

Register for Full Course