Are you considering learning coding and are you thinking about Python as a language? In this article I will answer some of the burning questions you might have.
Learning Python coding is one of the top skills in today’s IT industry. That’s because the Python programming language can be used for several purposes. You can use it to create web applications, APIs, standalone applications, artificial intelligence (AI) applications, scripts, videogames and much more.
Do you want to be able to start coding fast and build a skill that will make you valuable in today’s market? It’s time to learn Python.
Let’s answer some common questions!
What is Python Coding Used For?
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 definitely do that. And just with few lines of code.
- Videogames: let’s not forget about having even more fun with programming. Using Python you can create videogames 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 definitely easier to learn as programming language compared to other languages like Java or C++.
One of the main reasons…
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 with 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 perform 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 value 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 informations throughout this tutorial to start making you familiar with Python.
You will have the opportunity to fully understand this when you start coding.
How Do I Start Coding in Python?
To start coding in Python you have two options:
- 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).
- 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?
As mentioned before…
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 I have mentioned in the previous section 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 I forget the last parenthesis in the print line:
>>> print("I want to learn Python" ...
When I press enter the next line of the Python shell starts with … and that’s because the interpreter is telling us that there is something missing in our code.
>>> print("I want to learn Python" ... ) I want to learn Python
If I add the missing parenthesis ) the Python shell completes the execution of our code (see above)
I hope it makes sense 🙂
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:
Can I Learn Python in 3 Days?
We live in a world where we want everything fast…
If this is your approach to Python and programming in general you might get disappointed.
Learning programming takes consistent practice and time.
If you have used other programming languages before (e.g. C, Java, PHP) then you could write a first basic Python program in 3 days.
Ideally you could start by:
- Taking some simple code you have written in a different language you are comfortable with (no more than 10 lines).
- Writing the same code using the Python shell to start becoming familiar with Python syntax.
- Executing the Python code to make sure it does what you expect.
If you have not used other programming languages before don’t expect to become a master in 3 days. Just focus on learning basic Python expressions and focus on daily progress, nothing more.
I have written a simple Python checklist you can use to get started. You can focus on this one in the first 3 days.
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:
- Week 1: Install Python on your local machine, complete the Python Starter Checklist.
- Week 2: Learn how to work with Python strings.
- Week 3: Learn how to use the input() function and if else statement (conditional statement).
- Week 4: Learn how to use the Python for loop.
Make sure to write the code in the tutorials above in 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 to the point where you are comfortable with the code explained in the tutorials above before the end of the month. At that point try to write a simple program by yourself…
…just use what you have learned in those tutorials.
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 common roles you can apply to if your aim is 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 build the foundation of your Python knowledge.
Python Coding Examples
Here are some coding examples that will give you an idea of how Python code looks like and what you can do with it.
By now you already know how to print a message so I won’t repeat it again 🙂
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) 41.902782
There are three things to notice in this code example:
- To define a tuple you use parentheses.
- The values in the tuple (items) are numbers (integers) instead of strings like we have seen in previous examples.
- To access the first item in the tuple you use the syntax: tuple_name[index_of_the_item].
Note: indexes for tuple, lists (in Python they are called sequences) start from zero. That’s why when we pass zero between square brackets we 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. For example, you can obtain the same result with a for loop or a list comprehension.
Also, here are some coding exercises you can use:
- Remove spaces from a string.
- Reverse a Python string.
- Check if a Python string contains a number.
- Extract even and odd numbers from a list
- Get every other element from a list
- Check for duplicates in a list
- Convert a tuple to a list
- Generate random data
- Write a list to a file
If you don’t understand something (let’s say writing to a file) focus for a day on that topic, try to write your code using that construct again and again until it’s clear.
Remember, learning often comes from struggles. So, if you are struggling with something don’t worry, that’s a sign you are learning 🙂
This article will help you get started with Python and I hope it has given some more clarity on the direction to move towards.
I have written it to give you a detailed set of steps to follow to get comfortable with Python instead of having to waste time searching around and watching random videos.
This is an exciting journey, a journey in which you will discover that you can do so much more than you think possible.
Welcome to the world of Python!
And if you have any questions feel free to email me at firstname.lastname@example.org.
I’m a Tech Lead, Software Engineer and Programming Coach. I want to help you in your journey to become a Super Developer!