2016-03-30



Image source: pixabay.com

So, recently I was talking to one of my colleagues in my office on programming and stuff. He is a C and Java developer. He was informing me how Java has captured the world and it is used everywhere. Since I love Python  programming to the core though I am not a python freak, I just told him that Python is not way behind. But I was totally ignored for the fact that Java is more common these days. So I was not satisfied with the debate I had. I have been developing programs for Python since a long time and the one thing I know for sure is that Python is ‘n’ times easier than Java. Though people coding in Java would obviously start an argument about portability and stuff. But I would tend to ignore them however. So, the point I would be talking about today is how python is more useful and handy, especially how it is useful to get started for beginners. So Welcome to the Beginners Guide to Python Programming.

Why to Start with Python

So first things first, why to start with python programming as a beginner? Is Python a good start for beginners? You may have heard people starting with C as the basics. C is good. Infact its better than Python, but only if you have a good background in programming or atleast if you the basics of programming. But as a pure beginner? I dont think so. I myself started with C, but after 15 days of learning, and when I say 15 days, I mean 1 day=16 hours of practice.

So, when I started learning C, the part where I got stuck was pointers. It was too difficult to understand (at that point of time). I came from a hardware background, and trust me, it was not easy. So, since I had no one to guide, I started learning Java which was another blunder from my end. And again, I realised that Java is even tougher than C. So, being confused and irate, I started looking online communities for help like stackoverflow.com, github and the one thing I realised was that I had no proper guide. The reason I started with C and then later Java is because, few random people who did learn Java and C gave me the idea stating that Java and C are more widely used and its one of the easiest programming language. I wish I could meet that person to show him exactly what it meant to a beginner. But Nevertheless I received enormous help from these web programming communities and Ubuntu forums and realised that there was a language known as Python which I had actually never heard of. I googled a lot for 6-7 days and then I realised this is what I have been looking for my whole time. Python progrmming has a diverse and large community. Its fully open source, which means anyone can do whatever they want with it. Besides, what I learnt in C in those 15 days, I covered all of those things in Python in just a matter of 3-4 days. Besides, Python programming was so interesting as a beginner, than I didnt realised that I have covered so much topic until the 10th day of learning. Hmmm…enough with the numbers talk, let me give you a practical example for that.

Following is an example to print “Hello World” in C, C++ and Java:

C Programming:

#include<stdio.h>

main()

{

printf(“Hello World”);

}

C++ Programming:

#include<iostream.h>

main()

{

cout << “Hello World”;

return 0;

}

Java Programming:

public class HelloWorld {

public static void main(String[] args) {

System.out.println(“Hello World!”);

}

}

Python Programming:

print(“Hello World”)



Yes. I have written commands here to output the same thing to print “Hello World” on the screen, but as you can see the syntaxes(or commands to be more specific for a beginner) in C, C++ and Java need explanation, whereas the one in Python does not. Even a person without any basic knowledge of computer can understand that it prints Hello World. Yes, and thats how easy python programming is. If you dont understand any command above right now, dont worry, I will be explaining that later on in the blog.

Some Beginner Stuff



So before we proceed on to the higher stuff, lets get through the basics first. The first thing you need to understand as a beginner and the mindset you need to start programming is that you will never have the proper answer for whatever you code. Once you have the necessary knowledge, you may feel the need to write some of your own automated programs, and you may also succeed. But most of the times, you may feel that the programs written are not that fast, or at least slower than what you write in some other languages. For example, a program written in C will be 10 times faster than python programming. But that doesn’t mean python is slow. It just means you need to find a way to make it faster. Obviously it will never be as fast as C, but it will obviously be less time consuming than writing and compiling a program in C or Java. Besides, its easier to debug someone else’s program in Python since the syntaxes are easier to understand, than to read a program without comments in C or Java.

Also, remember never to compare two distinct languages when learning. You may say that I am speaking irony, since I myself compared C with Python, but that I did stating Python is good for a beginner. C has its own set of advantages and backlashes and similar do Python progrmming. But as a beginner, python is the choice. So, thats it for the beginner stuff, lets check some real-life applications of Python

Where is Python Programming used

Image source: pixabay.com

As for any official answer, I would suggest you to take a look on the official python website:-

To explain it in simple words, python is almost used everywhere. Google itself was using python in its database management for a long time before it switched to C. Python programming is used a lot for automating web related apps, and especially in the field of Maths, science and robotics. If you have exclusive interest in python, then once you learn it, I would recommend you to take a look at Raspberry pi and the Arduino chip. Its an extremely capable microprocessor to work hand-in-hand with python Programming.

Besides, let alone the fact that there is no beat to Python’s Django Framework for web development. For beginners, once you get the basics cleared with Python, you can even take a look at Django, which is a framework built on python to develop web related to apps. Some famous sites built on django would be social networking sites like the Instagram and Pinterest, or community sites like Mozilla Support, Reddit gifts and gaming sites like the Chess.com which has a legacy in the Chess game. Along with web development, python is also used in embedded scripting, 3D softwares like Maya, Quantum GIS and a lot more. So, these things prove that though Python is not known for being used in high-end performance applications, since it is not, it is still the people’s choice for doing a lot of other work. Now we know what Python is capable of, lets take a look at how to get started with it.

The Pre-requisites

Frankly speaking, there is no as to specific prerequisites for learning Python. Python is such an easy language that its mostly people’s primary or the beginner choice of learning, which makes itself the prerequisite for learning anything else.

But this makes Python a bit too overwhelming. If you tend to keep your mind straight when learning which mostly doesnt not happen, then there is no issue in learning python as a primary language. What I mean by keeping the mind straight is that, normally when people learn python, they get too used to the simplicity of python since they are just beginning to learn python. Python developers can code enormous amounts of code in a decently simplified manner. But if you want to go beyond python and learn other languages after that such as Java, C, Scala or haskell then this may become any obstacle. The primary reason for that is because once people become habitual to python, the coding and complexity for the likes of C and Java tend to get rather irritating. Especially the pointers and the vast libraries wil go over and above the head to a beginner.

So, my point being, if you plan to further your career on just languages like Python, Ruby or Perl then there is no problem in learning Python Programming as a beginner. But if you want to be a multi-discipline ninja in programming, then I would recommend you to learn C or Java first, and then learn python because that way, you would learn C and Java the hard way, and since you know how to code, learning Python Programming will just be a piece of Cake.

Python vs The World

So, now we are wise and know how python and C works. We already saw how python can be used in the outer real world. But lets take a look at how it can affect our daily lives as well. Python is extremely useful when it comes to automation. For example, lets say you have a lot of social accounts, and you have a lot of passwords. Since we programmers are paranoid, we tend to keep different passwords for every other Website account we have. But who has the time to remember all these stuff. As a matter of fact, even if we try to study it, once we change a password, we would still have to remember which ones we changed and such similar stuff. So, normally people write it down on a piece of paper, or atleast tech freak people like me use a notepad application on cell and laptop. But still if someone gets their hand on them, it still is risky. Now there are other methods, where you can buy a password saver, but is it really worth it? Yes, and here is where python comes in between. I had this similar issue, and I actually stumbled on to something when I was learning dictionary and conditions in python.

Since, it would be hard for you to understand if you are a beginner in python Programming, i would be writing pseudo codes here to make it understandable for you. Now, python has dictionaries and conditions. Conditions use if, elif and else to complete a statement. It goes something like this:

if I don’t go to work;
make me a coffee.
else
dont;

Now you get my point? Yup, that was a pseudo code, which means I could also do something like this:

if password=iamsmart
proceed to step two
else
print “invalid password”

Now, I as soon as I start my notepad file made in python, it would ask me to enter a password, if I enter it then it will allow access, else it wont. And I combined this with dictionaries. Dictionaries are something which can be used to call out other stuff stored inside. A good example would be a virtual telephone book. For example, in a pseudo world, it would go like this:

Book = { Adam : { phone :1234, address: RoomNo.1},
Eve : { phone : 5678, address: RoomNo.2},
Smith : { phone : 9012, address: RoomNo.3} }

Now, this my friend is called as a pseudo dictionary. Here the Book is the dictionary here and it has contents in the form of Adam, Eve and Smith. Now, when I call for the dictionary, it will ask me to enter a name. When I enter a name, it will give me its contents i.e. the phone no. and the address. This is how a dictionary works in python Programming. So, what I did was to change the name to websites and phone numbers to passwords. And not only, did I do that, but I also added the if else condition to it, after which it looked like this:

if password=iamsmart
proceed to step two
else
print “invalid password”

LockBox = { Gmail : { Password@1 },
Facebook : { Password@2 },
Instagram : { Password@3 } }

I also did a bit more modifications, but as far as you are concerned, as a beginner this is extremely good. Now, whenever I wanted to login from someone else’s computer or cell phone or my work place, I would save this small python file converted into an executable with the help of py2exe on my pendrive. So, it first asks for password, if it is right it then asks which password do you want to check, else it kicks me out.

Later on, I added some PGP encryption to this stuff to make it more secure. But now you know, what it means to learn python. It is not only a simple language to learn, but also useful. If you to become an extreme programmer, I would recommend learning C or Java and then Python Programming , else if you are just a beginner like I was and want to do some cool automation as a hobby, then there is nothing better than using Python.

The post Beginners Guide to Python Programming appeared first on eduCBA.

Show more