Basic Python skills everyone needs to start their coder journey, first part

What is python

Python is a high level computer programming language easy to learn and can be simply put in use by anyone who is passionate about coding. The first time I started reading some python code it felt like i was reading myself, I mean my thoughts converted to code.

Heavily used by Google and Youtube python is becoming very popular among computer programmers all over the world especially in the startup world as it features rapid development making it the swiss army tool for prototyping.

Why learn python

Many of you may ask why learn python and not java or another programming language. This is the right question to ask for a starter in the coding world and I will list some arguments below why one should start learning python as their first computer programming language.

What's the one thing every developer wants? More screens! Enhance your coding experience with an external monitor to increase screen real estate.

It will take you probably two weeks to learn all the python syntax needed to build real world applications. Or just a few days if you are a passionate reader about these kind of topics.

The fact python is easy to read makes it easy for you as a developer to maintain the code of your project. As the project grows in terms of code you don’t want to come back after your holidays and when looking at the code you have written, not understanding at all how it really works under the hood.

I have had the chance to talk to a python developer who did perl programming for a living back in the days and he told me it is real hard to maintain the code of his old projects. Not hard, but real struggle!

Python is fully Open Source which means that you can look at its implementation code and understand stuff from a lower level perspective.

You can code python on almost any platform. Telling from my experience I have been able to run my python scrips in both Windows and Linux operating systems except for Mac because it is such an expensive toy for me, but for sure you can code python on Mac too.

Python is not just a language. It has a big community behind who is very welcoming and it makes you feel like Home. I am very happy to have met so many python developers in Firenze Italy back in 2013. I felt real love in there.

Some technical knowledge on python

You can notice a python file by the .py extension. Every file that ends with this extension is classified as a python module. For example the following is a python module.

pythongeek.py

The module serves as a container for the python code of our app and we can use the code of a module in other modules by importing it with the import statement like shown below, but do not try to understand this thing right now as this tutorial is just an introduction. I am sure some things may not make sense to you right now and that’s alright.

import pythongeek # imports the pythongeek module

Since python is an intepreted language you will need the official python intepreter to run python code on your machine. In most linux distributions such as Ubuntu it comes installed by default, but in Windows you have to install it yourself.

Having struggled myself with the installation of Python 2.7 on my Windows 7 machine, I decided to write a concise and easy to follow tutorial for everyone on how to download, install and configure Python 2.7.11 on Windows operating system. The tutorial is published on this website, make sure to check it before going any further, especially if you’re using Windows 7 as your main operating system.

Learn and build the basic Python coding skills

Now that you have python available on your machine it is time to build some basic coding skills to build the foundations for further development.

Now that you have a python interpreter in your machine it is time to start some coding. To open the python shell on windows just go to Start and in the search box type python.

Then click on IDLE (Python GUI). The following python graphical shell will come up.

Those who make use of Linux based operating systems, can follow this tutorial too as the python syntax is the same, it does not change per os. So open your terminal, and start to follow.

The above screenshot shows the graphical Python shell supported by Windows machines; for the purpose of this tutorial we are going to use this shell.

Variables

The first thing you need to learn in python is how to declare a variable. You can declare a variable in python like shown below.

a = 5

Where a is the name of the variable and 5 is the value this variable is linked to.

To get the value of the variable you type the name of it and hit Return (Enter) on your keyboard.

python basics

You can also do some maths in Python. The following is a simple arithmetic operation which the Python programming language supports.

a +1

Tuples, Lists, and Dictionaries

Let’s get more pythonic. There are special builtin datatypes in python such as the following:

  • Lists
  • Tuples
  • Dictionaries

There are many others, but for the purpose of this tutorial we will take a look at the ones listed above.

Let’s take a look at lists. For example the following is a list assigned to variable l.

l = [‘python’, ‘geek’, ‘google’, ‘youtube’]

python basics

Lists elements can be accessed and used in a program. For example to access the first element of the list you use the following syntax.

l[0] # where l is the list and 0 is the index of the first element

python basics

So to access the second element you do the following.

l[1]

A list can be updated. For example you can change the first element in our list by doing the following.

l[0] = ‘ruby’

As you can see, when printing the new list the first element is updated.

l

python basics

We will cover lists in more depth in specific tutorials. Now it is time to learn about tuples.

You can define a tuple like shown below.

t = (‘python’, ‘geek’, ‘internet’, ‘skype’)

python basics

The same as in lists you can do indexing in tuples too. For example to get the first element of the above tuple you do the following.

t[0]

python basics

So tuples are like lists? Not really!

Try to update the first element of the tuple we have and see what happens.

t[0] = ‘ruby’

python basics

Let’s move to dictionaries. For example the following is a python dictionary.

d = {‘name’: ‘pythongeek’, ‘occupation’: ‘maths’, ‘age’:13}

python basics

Each item of the dictionary is composed of two elements: a key and a value. For example the first item of our dictionary is composed of the key ‘name’ and the value ‘pythongeek’.

Try the following.

d[‘name’]

python basics

As you can see you access the value of an item in a Python dictionary by its key.

Final thoughts

Before one can code any big application or project in Python, they need to learn and master the basics of this amazing computer programming technology. In the next part, codetheory.in will share more python knowledge one needs in order to progress in their coding journey.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Leave a Reply

Your email address will not be published. Required fields are marked *