Getting Started with Python on Google Collab: A Beginner's Guide


Google Collab is a powerful online platform that allows users to write, run, and share code in a variety of programming languages, including Python. With Google Collab, you can work on your coding projects from anywhere, at any time, without the need for a local machine or expensive hardware. In this article, we'll go over the steps to get started with Python on Google Collab, so you can start coding right away.

Step 1: Creating a Google Collab Account

To use Google Collab, you'll need a Google account. If you don't already have one, create a new Google account by going to the Google Collab website and clicking on "Sign in". Once you've signed in, click on "Create a new notebook" to get started.

Step 2: Setting Up Your Environment

Once you've created a new notebook, you'll need to set up your environment. In the top left corner of the screen, click on the three vertical dots to open the menu. Select "Notebook settings" from the drop-down menu. In the Notebook settings window, select "Python 3" as the runtime, and make sure the "Enable GPU acceleration" option is turned off. Click "Save" to save your changes.

Step 3: Installing Libraries

Next, you'll need to install the necessary libraries for your project. To do this, click on the "!" icon in the top left corner of the screen. This will open the command line. Type !pip install <library_name> to install a library. For example, if you want to install the popular NumPy library, type !pip install numpy. Press enter to execute the command.

Step 4: Writing Your First Script

Now it's time to write your first Python script! In the main text area of the notebook, type the following code:

print("Hello, World!")

This code will print "Hello, World!" to the output area below the text area.

Step 5: Running Your Script

To run your script, click on the "Run" button or press Shift+Enter. The output will appear in the output area below the text area. You can also add more lines of code to your script and run them individually by selecting the lines you want to run and clicking the "Run" button.

Tips and Tricks:

  • Use the % symbol before a cell to comment out the cell. This will prevent the cell from being executed when you run the script.

  • Use the Shift key to highlight a block of code, and then use the Ctrl key plus the direction keys (up, down, left, or right) to move the block around.

  • Use the Ctrl key plus the letter C to copy a piece of code, and the Ctrl key plus the letter V to paste it elsewhere.

  • Use the Ctrl key plus the letter Z to undo changes, and the Ctrl key plus the letter Y to redo changes.


In this article, we've covered the basic steps to get started with Python on Google Collab. We've shown how to create a Google Collab account, set up your environment, install libraries, write your first script, and run it. With these skills, you're ready to start working on your own Python projects on Google Collab. Happy coding!

Did you find this article valuable?

Support TheMehranKhan by becoming a sponsor. Any amount is appreciated!