A guide to Python programming using Google Colab
Python is a versatile programming language widely used in various fields such as web development, data analysis, artificial intelligence, scientific computing, and more. This article explains how to perform multiple programming tasks using Google Colab, a popular cloud-based platform for coding.
Python is a high-level programming language. It was first released in 1991. It became popular due to clear syntax and simpler coding processes compared to C++ and Java. It is preferred over other coding applications because of:
- Ease of Learning: Its simple and intuitive syntax makes it accessible for beginners.
- Strong Community Support: A large, active community means extensive resources, documentation, and third-party libraries are readily available.
- Versatile Applications: It can be used in many domains like web applications and machine learning.
- Free and Open Source: Python is free to use and share.
Starting with Python
There are several libraries and environments available for Python development, each catering to different needs.

- Integrated Development Environments (IDEs)
- PyCharm is a robust IDE with features like code analysis, debugging tools, and integration with version control systems. It is particularly well-suited for larger projects.
- Visual Studio Code is a lightweight and highly customizable code editor that supports Python through extensions, offering features like IntelliSense, debugging, and Git integration.
- Jupyter Notebook is an open-source web application that allows users to create and share documents containing code, equations, visualizations, and narrative text. Jupyter is especially popular in data science and academia.
- Text Editors
- Sublime Text is a fast and responsive text editor that supports multiple programming languages, including Python. It offers features like syntax highlighting, code snippets, and customizable key bindings.
- Cloud-Based Platforms
- Google Colab is a cloud-based Jupyter Notebook environment that allows you to write and execute Python code directly in your browser. It is especially popular for machine learning tasks due to its free access to GPUs and TPUs.
- Kaggle Kernels is a cloud-based environment that supports Jupyter notebooks and provides access to datasets and machine learning resources, ideal for data analysis competitions.
- Package Management
- PIP is a package installer for Python, allowing you to install and manage additional libraries and dependencies easily.
- Anaconda is a popular distribution that simplifies package management and deployment for scientific computing and data science, including a package manager called Conda.
Focussing on Google Colab
Google provides a Jupyter Notebook-type interface for running Python code on an online virtual machine such as Google Colab. Google Colab comes with many popular Python libraries pre-installed, such as numpy, pandas, matplotlib, and tensorflow. Colab allows for seamless collaboration, much like Google Docs. You can share your notebook with others, giving them access to view, comment on, or edit the notebook. This feature is particularly useful for team projects, code reviews, and peer learning. Colab autosaves work progress in Google Drive. You can also download notebooks in several formats to work offline or integrate them with other tools.
Getting started with Google Colab
- Go to Google Colab.
- Connect it with Google Drive.
- Colab allows you to mount your Google Drive, making it easy to access, read, and write files directly. This feature is beneficial for loading datasets, saving processed data, or storing outputs and models. Enter the below command in the command box to connect Colab with your Drive folder:
Colab allows you to mount your Google Drive, making it easy to access, read, and write files directly. This feature is beneficial for loading datasets, saving processed data, or storing outputs and models. Now you can start writing your code and saving it to your Google Drive.

Google Colab with Generative AI
Google Colab supports generative AI tasks like natural language generation and image synthesis. These features also make working with other AI models easier without needing advanced configurations or large-scale data processing.
- Click on generate with AI in your Google Colab notebook.
- Type in your prompt and press enter.
- Type your prompt and click enter.
- Once you get the code run the code for the output.
Python basics that are foundational
Declaring a variable
a = 10
print(a)
#OUTPUT
10
Adding a comment to the line of code
a = 10 #This is a variable with a value of 10
print(a)
#OUTPUT
10
Adding multiple lines of comments to a section of code
a = 10
"""
This comment can span multiple lines without #.
It can be used to explain complex codes.
Print is a Python function.
"""
print(a)
#OUTPUT
10
It is critical to use indents to structure and organise blocks of codes.
#Checking eligibility of a person to vote
age = 10 #Any rendom integer can be assigned to the variable age
if age >= 18:
print("Eligible to vote.")
else:
print("Not eligible to vote.")
#OUTPUT
Not eligible to vote.
Improper indentation will lead to IndentationError.
Determine the type of a variable value
a = 10
type(a)
#OUTPUT
int
Assigning multiple values or variables
a, b = 10, 11
type(a)
print(b)
a = b = 1
print(a,b,c)
#OUTPUT
int
11
12
1 1 1
Different types of data serving different purposes in Python
- A string is a sequence of characters that is defined using single quotes, double quotes, or triple quotes.
- Integers represents whole numbers, both positive and negative.
- Float represents decimal numbers.
- Boolean represents True or False.
- List is a mutable sequence of items, which can be of mixed data types.
- Tuple is an immutable sequence of items, similar to a list but cannot be changed after creation.
- Dictionary is a collection of key-value pairs, where keys are unique.
Explicitly changing the type of data
a = "10" #Intentionally assigning a string value
b = int(a)
c = float(a)
d = str(b)
print(type(a),type(b),type(c),type(d))
#OUTPUT
<class 'str'> <class 'int'> <class 'float'> <class 'str'>
Various arithmetic operations in Python
x = 10
y = 5
print(x + y) #Addition
print(x - y) #Subtraction
print(x * y) #Multiplication
print(x / y) #Division
print(x // y) #Floor division
print(x % y) #Modulus or remainder
print(x ** y) #x raised to the power y
#OUTPUT
15
5
50
2.0
2
0
100000
Loops to iterate characters of a string
name = "krishna" #Variable declared
for char in name:
print(char)
#OUTPUT
k
r
i
s
h
n
a
Length of a string
name = "krishna" #Variable declared
print(len(name))
#OUTPUT
5
Replacing and concatenating words of a string
greeting = "Good morning" #Variable declared
print(greeting.replace("morning", "afternoon") + " everyone")
#OUTPUT
Good afternoon everyone
I am an interdisciplinary educator, researcher, and technologist with over a decade of experience in applied coding, educational design, and research mentorship in fields spanning management, marketing, behavioral science, machine learning, and natural language processing. I specialize in simplifying complex topics such as sentiment analysis, adaptive assessments and data visualizatiion. My training approach emphasizes real-world application, clear interpretation of results and the integration of data mining, processing, and modeling techniques to drive informed strategies across academic and industry domains.
I am a management graduate with specialisation in Marketing and Finance. I have over 12 years' experience in research and analysis. This includes fundamental and applied research in the domains of management and social sciences. I am well versed with academic research principles. Over the years i have developed a mastery in different types of data analysis on different applications like SPSS, Amos, and NVIVO. My expertise lies in inferring the findings and creating actionable strategies based on them.
Over the past decade I have also built a profile as a researcher on Project Guru's Knowledge Tank division. I have penned over 200 articles that have earned me 400+ citations so far. My Google Scholar profile can be accessed here.
I now consult university faculty through Faculty Development Programs (FDPs) on the latest developments in the field of research. I also guide individual researchers on how they can commercialise their inventions or research findings. Other developments im actively involved in at Project Guru include strengthening the "Publish" division as a bridge between industry and academia by bringing together experienced research persons, learners, and practitioners to collaboratively work on a common goal.

Discuss