Monday, June 9, 2014

2.1 Introduction to Python programming language

Well, for those who are interested in programming, I will be doing up a Python programming tutorial as well. Since I am taking a Coursera course on this, I think I would be able to learn better if I try to do up tutorial and try to explain the topic according to my understanding. As usual, if you realize that there is something wrong with my post, please inform me about it and I will check and amend it. Bear with me as I am learning as well.

For this post, we will learn how to install Python on our computer. Then, we will touch a little bit on how to program using Python on our computer. So let's get started.

Basically, Python is a programming language written by Guido Van Rossum. It's actually a language which helps us to communicate with the computer. It enables us to 'talk' to our computer, crafting a program to solve the problems we might have in reality. Before we dig deeper, we would need to install the Python application into our computer before we can experience programming in Python.

So here is the link: https://www.python.org/downloads/. Well, most python releases are open source and hence, most of it are free-to-use applications. It's great for beginners as we might not have the funding for us to get an expensive software just to learn programming.

https://www.python.org/downloads/
Upon clicking on the link, you will see the page above. There are two choices: Python 3.4.1 and Python 2.7.7. The one I am using will be the version 2.7.7. You can click on the "Download Python 2.7.7" and your browser will download the file for you. After which, you will need to execute the file and install python accordingly. There is a point to note, the above downloads are for Windows operating system. Hence, if you are using Mac OSX or Unix, you should click on the circles to change the downloads with regards to the operating system that you are using.

That's it, you have python installed in your computer. Mine is installed in my local C drive, and yours might be in a different drive depending on where you choose to save your program. However, the default selection would normally be the default drive on your computer.


So, let's find our file and execute the one with "Python (command line)" so that we can type in our command for the computer. As you can see from the top left hand side of the windows, "C:\Python27\python.exe" shows that my Python is in C drive and inside the file named "Python27". In the window, they will reflect what version of Python you have,  mine is 2.7.7 and yours might be a different version if you choose to download the version 3 of the application.

Now let dig deeper into the application. You can see the ">>>" and wondering what is this doing in my application. What does it want me to do exactly? The symbol >>> represents the application prompting or 'asking' you for instructions or command. Hence, let's try to type something inside the application.


Well, here we are. I have typed "Hi There!!" to Python, and yet I received something weird in return. So what went wrong with this? Well, we all know that computers behave differently from humans. Hence, the language they can understand also differs from our human language. In programming language, we will need to follow a set of rules and use the words that Python actually understands to communicate with the computer itself. We cannot say whatever we want to the computer and expect the computer to understand us. Instead, we should learn how the computer understands the command by learning the structure and functions that are available in Python for us to communicate with our computer. What I can say is we have to be really patient while learning as there a quite a number of functions and commands we need to learn. Some times it might take a while for us to understand what a function can do. Don't be demoralize by that and try to practice and explore more, you will get it as you experience hands on with Python. Just reading the tutorial or watching the lecture is not enough for programming. Practice and exploration are as important for you to pick up the skill. Having much said, let's try something that the Python would understand and gives us a response.


Now, we are able to see some response from our computer. Try typing in "print 'Hi Everyone!'" into your Python application and you will see the computer responding "Hi Everyone!" below your command. It is pretty intuitive what we are asking our computer to do for us. Basically, the 'print' is a reserved word in Python and whenever you type print in your command line, you are asking the computer to print out what ever that follows. After print, we keyed in "Hi Everyone!", we had to include inverted commas to indicate the at Hi Everyone! is a string that we want to print. If you don't include the commas, the computer can not identify what type of information you typed in. We would go through the various types of information available in Python in details in the upcoming tutorial.

You can try changing the words within the inverted commas and explore what the program would do.

I might be posting another tutorial later in the day if I have sufficient time. Hence, you can try exploring on your own to find out more about the programming language.

Thank you for reading. Have a great day ahead.

No comments:

Post a Comment