The easiest way to get started with Python is to use Google Colab since it does not require the installation of Python or any kind of software. It even comes with most important libraries installed.
Using Google Colab, you will be able to get started in Python without the complex process of actually installing the software.
Next, the easiest way to work with Python is to start with the basics of the Python syntax and learn how to read Python error codes. You will likely face multiple errors in learning Python. You want to understand early on what the errors mean.
Get Started with Python in 5 Simple Steps
The simplest way to get started with Python is to use these 5 simple steps:
- Run Python in Google Colab
- Learn Basic Python Concepts (e.g. printing, commenting, data types, variables)
- Learn about the Python Syntax
- Learn how to Install and import Python Libraries
- Learn how to Read & Debug Python Errors
1. Create a Python Notebook in Google Colab
Google Colab is the easiest Python IDE as it comes with Python and multiple useful libraries installed in a simple browser-based environment.
Create a Python Notebook in Google Colab
Go to Google Colab and click on New Notebook. (You will get one of the following screenshots whether you are logged-in or not)
Run Your First Python Code in the Colab Notebook
Add Your Python Code into one cell of the Colab Notebook.
You can try this code:
print('hello world')
Click on the symbol next to the cell to run the code.
See how simple it was to run your first Python code. To learn more, see how to use Python in Google Colab.
2. Learn Basic Python Concepts
After you have run your first, Python code, make sure that you understand the basic concepts in Python: how to print, how to create variables, main data types and python operators.
# Printing text
print('hello')
# Making a comment (this line will return nothing)
# Creating a variable
variable = 'this is a variable'
print(variable)
# Python data type
a_string = 'hello' # this is a string
another_string = '1' # this is a string
a_int = 1 # this is an integer
a_list = [1,2,3] # this is a list
a_dictionary = {'a':1, 'b':2} # This is a dictionary
# Python operators
print(1 + 1) # returns: 2
print('1' + '1') # returns: '11'
If you are interested, look at my article to learn more about the basic concepts in Python.
3. Learn about the Python Syntax
The simplest way to get started in Python is to understand the Python syntax and the kinds of errors that you can get. Python is built in a way that it forces the user to write code in a certain way or else it will break. This is, among other things, to ensure that code is written with a certain standard that make it more readable.
The main thing to know is that indentation matters, you need to close code blocks, you need a colon after a statement:
# Incorrect Indentation
if condition:
print("Indented incorrectly") # this code will return SyntaxError
# Correct Indentation
if condition:
print("Indented correctly")
# Incorrect closing of brackets
print("hello) # Missing closing quote
print(int("1") # Missing closing parentheses
# Missing Colon
if condition # Missing colon
# do something
def my_funct() # Missing colon
# do something
if condition: # Correct
# do something
def my_funct(): #missing colon
# do something
4. Learn how to Install and Import Python Libraries
When learning Python, you will need external libraries to leverage code created by others. To use external libraries, you need to learn how to install and import them into your Python script.
In Google Colab, many external libraries are already installed. Thus, to import libraries, use the import
statement with or without the as
alias (used to make code shorter).
# import without alias
import numpy
numpy.ones(4)
# array([1., 1., 1., 1.])
# import without alias
import numpy as np
np.ones(4)
# array([1., 1., 1., 1.])
If a library is not installed, you will get the ModuleNotFoundError
.
You can fix this by installing the Python library using pip
.
To do so, you would generally open the Terminal and use the pip install
command. In Google Colab, we will use the command pip install
with the magic character (%) that is used to perform an operation inside the Terminal from the Notebook.
%pip install advertools
Next, you can easily import the installed library.
import advertools as adv
adv.stopwords.keys()
5. Learn how to Read & Debug Python Errors
One of the most common challenges that people learning Python face is related to dealing with errors.
For example, if you forget to close a quotation for a string, Python will returns a SyntaxError.
There are many of such errors that can cause headaches. If learn how to read the Python Traceback (error output), it will quickly become easier.
The easiest thing to do here is to copy the error code in Google or ChatGPT and figure out what is going on.
Here is a simple ChatGPT prompt to help you fix code issues:
My Python code returns the following error:
SyntaxError: unterminated string literal (detected at line 1)
Here is my Python code:
>>> # your Python code...
Fix my code
Here is an example from my tutorial on how to read the Python traceback to help you get started with fixing Python errors.
To learn more about how to fix errors
What is the Hardest Way to Learn Python?
The hardest way to learn Python is to install Python on your computer and then find large piece of outdated code online and try to copy, paste and run the code without understanding what it does.
There are 2 versions of Python and if you find code written in Python 2 on a website and try to run it with Python 3, you will likely get syntax errors.
If you find code that has dependencies, you will likely face errors in your code too.
What is the Hardest Part of Learning Python?
The hardest part of learning Python is to install Python and debug errors. You can easily overcome this challenge by using Python in Google Colab and learning how to read Python errors and what the most common errors in Python.
SEO Strategist at Tripadvisor, ex- Seek (Melbourne, Australia). Specialized in technical SEO. Writer in Python, Information Retrieval, SEO and machine learning. Guest author at SearchEngineJournal, SearchEngineLand and OnCrawl.