How To Start Coding in Python?

Learning Python is one of the top skills in today’s IT industry because Python is used to build several types of applications. Some examples are:

  • Web applications: imagine you want to build a social network like Facebook, with Python you can do it.
  • APIs: API stands for Application Programming Interface and it’s a software that allows two systems to talk to each other and exchange data. For example, the Amazon mobile application talks to one or more Amazon APIs to provide functionalities to its users.
  • Standalone applications: you might want to build an application you can run on your computer that pulls data from the Internet and generates reports.
  • Artificial intelligence (AI) applications: you can create a neural network that allows you to predict future data based on an existing dataset.
  • Scripts: when managing Linux or Windows systems you might want to automate daily repetitive tasks. With Python, you can do that. And just with a few lines of code.
  • Videogames: let’s not forget about having even more fun with programming. Using Python you can create video games too!

If you are getting started with Python the first step is to understand how to write and run simple Python programs on your computer.

Those are basic programs written in a single file that have a .py extension. We will see how to execute them later in this article.

Is Python Easy to Learn?

Python is easier to learn as a programming language compared to other languages like Java or C++.

Python is easy to learn because its syntax is clear and very similar to plain English. The same doesn’t apply to other programming languages like Java or C++ that have a syntax that makes the learning curve steeper.

When you start coding in Python you will see how easy is to write your first program, especially if Python is not your first programming language.

And if Python is your first programming language don’t worry, its simple syntax allows you to get your first basic program written pretty quickly.

For example, if you want to create a program that prints the message “I want to learn Python!” you can use the following code:

print("I want to learn Python")

The reason why you can use print(“message”) in your code is that print() is a Python built-in function.

A function is like a small program you can use inside your program to execute a specific operation, in this case, print a message. When you call a function you add parentheses () next to the name of the function. Within parentheses, you specify the values you want to pass to the function.

Don’t worry if this is not 100% clear now, I just want to give you small bits of information throughout this tutorial to start making you familiar with Python.

You will have the opportunity to fully understand this when you start coding.

Where Can You Start Coding in Python?

To start coding in Python you have two options:

  1. Use a Python online interpreter: this is a simple web page that allows you to write Python code (on the left side), execute it using the Run button, and see the output of the code (on the right side). This can be great to get started because you can write basic code without having to install Python on your machine. At the same time, I suggest you start using Python on your machine as soon as you can (point 2).
  2. Use a Python installation on your local computer: download the latest version of Python available for your Operating System (Windows, Mac, or Linux), install it, and then open the Python shell to start writing code.

The following examples apply to both points 1 and 2.

The only difference between the two is that when you open the Python shell in your local Python installation you will see the symbol >>>.

This symbol appears when you open the shell and every time you type a full Python command.

Note: on Mac and Linux you can open the Python shell by simply typing the command Python in the Terminal. On Windows, you can use either the Cmd Terminal or one of the icons available after you install Python.
# python
Python 3.8.5 (default, Sep  4 2020, 02:22:02) 
[Clang 10.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>

How Do You Write a First Python Program?

To write a first Python program open the Python shell on your local installation or use a Python online interpreter. Then write a print() statement that prints a message in the shell.

Let’s write the print() statement inside the Python shell:

>>> print("I want to learn Python")
I want to learn Python
>>>

I have written the print command and then pressed Enter. This is a full Python command and because of that the next line starts with >>> again.

This is the way the Python shell is telling us that it’s ready to accept another command.

Let’s see what happens if you forget the last parenthesis in the print line:

>>> print("I want to learn Python"
... 

When you press enter the next line of the Python shell starts with … and that’s because the interpreter is telling you that something is missing in the code.

>>> print("I want to learn Python"
... )
I want to learn Python

If you add the missing parenthesis ) the Python shell completes the execution of our code (see above)

Please try this either on the Python online interpreter or in the Python shell of your local installation.

Those of you who will try this on the Python online interpreter will see an error message:

Python online interpreter

Can I Learn Python in 3 Days?

Learning programming takes consistent practice and time.

If you have used other programming languages before (e.g. C, Java, PHP) then you could write your first basic Python program in 3 days.

Here is where you can start:

  • Take some simple code you have written in a different language you are comfortable with (no more than 10 lines).
  • Write the same code using the Python shell to start becoming familiar with Python syntax.
  • Execute the Python code to make sure the program works.

If you have not used other programming languages before don’t expect to learn Python in 3 days. Just focus on learning basic Python expressions and focus on daily progress.

Can I Learn Python in a Month?

One month is enough time for you to plan your Python learning and to see some results. You can use the following schedule as a plan you can follow:

Make sure to write the code in the tutorials above using your Python shell. Don’t just go through the tutorials without practicing. The real learning happens when you type those Python lines of code by yourself.

You can get comfortable with the code explained in the tutorials above before the end of the month. At that point try to write a simple program using what you learned.

Is Python Enough to Get a Job?

Learning Python is enough to get a job as a Junior Developer. A Python Backend Developer is one of the roles you can apply to if want to focus just on Python. If you learn Python and you have existing Operating Systems knowledge then you can also apply to DevOps Engineer roles.

To apply to any roles where the main requirement is knowing Python you have to become very comfortable with:

  • Python basic data types: strings, integers, booleans, tuples, lists, dictionaries.
  • Conditional statements: if, else, elif.
  • Looping constructs: for loop, while loop, list comprehension.
  • Functions: show how you can create reusable code.
  • Working with files: reading from a file and writing to a file.
  • Solving the same problem in multiple ways: show flexibility in the way you solve problems with Python.

In the last section of this tutorial, you can find some exercises to go through to start building the foundation of your Python knowledge.

Python Coding Examples

Here are some coding examples that will give you an idea of what Python code looks like and what you can do with it.

1. Modify a string by replacing the word “coding” with the word “Python”

>>> message = "I want to learn coding"
>>> new_message = message.replace("coding", "Python")
>>> print(new_message)
I want to learn Python

We use the = sign to assign a value (on the right of the = sign) to a variable (on the left of the = sign).

Note: a string is a data type used to represent a word or a phrase.

2. Define a list of strings

>>> animals = ["dog", "cat", "lion"]

The data inside a list is enclosed within square brackets. Each value in the list is a string because is delimited by double quotes.

3. Print the elements in a list using a for loop

>>> for animal in animals:
...     print(animal)
... 
dog
cat
lion

As you can see you can type code on multiple lines using the Python shell.

4. Add an element to a list

>>> animals.append("tiger")
>>> print(animals)
['dog', 'cat', 'lion', 'tiger']

The .append() part of the command is called append method and it’s a type of function that can be used to add an element to the end of a list.

5. Print the first item of a tuple

>>> coordinates = (41.902782, 12.496365)
>>> print(coordinates[0])
41.902782

There are three things to notice in this code example:

  1. To define a tuple you use parentheses.
  2. The values in the tuple (items) are numbers (integers) instead of strings as we have seen in previous examples.
  3. To access the first item in the tuple you use the syntax: tuple_name[index_of_the_item].

Note: indexes for tuples, and lists (in Python they are called sequences) start from zero. That’s why when you pass zero between square brackets you get back the first item in the tuple.

Python Coding Exercises

You can come up with coding exercises by yourself. Think about a simple problem you want to solve and then try to find multiple solutions to it using different Python constructs.

Also, here are some coding exercises you can use:

If you don’t understand something (let’s say writing to a file) focus for a day on that topic, and try to write your code using that construct again and again until it’s clear.

Learning often comes from struggles. So, if you are struggling with something that’s a sign that you are learning.

If you have any questions feel free to email me at hello@codefather.tech.

Leave a Comment