Connect with us

Python Programming for Beginners – Top Reasons to Learn Python Instead of C/C++ First

python banner

Programming

Python Programming for Beginners – Top Reasons to Learn Python Instead of C/C++ First

Do you know about world’s top software technologies? Python is ranked #2 in USA (Accordingly Google trend data from June 2016). Wondered why Python is so popular? Do you want to learn Python programming and don’t know where to start? this article is for beginners who want to learn basics of Python programming including syntax and how to installation guide!

Let me explain a bit about Python – the most overheard interpreted language mentioned in geek-conversations between your colleagues, class-mates, or that tech meet-up you were a part of. A majority of people who have pursued their engineering in Computer Science or Information Technology from India were never taught ‘Python’ programming in the classroom; and yet many computer programming enthusiasts know how to write some beautiful code in Python!

What makes Python programming language so special?

Why is there such a hype about this language in India, even when most recruiters and companies which hire engineers in bulk aren’t even looking for the position of a Python programmer in their organization?

Well, there is a simple philosophy behind Python which appeals many out-of-the-box thinkers — actually, there is a simple statement which you can type in your Python shell to view the philosophy. We will shortly see how you can install and use Python, but just for informative purposes, here’s what the philosophy looks like:

Zen_of_Python
You may ask, “Okay, those are nice words, but what do I need them for?” If you did, then I bet you didn’t read more than 3 lines on that black screen because The Zen of Python is pretty self-explanatory about the way the language is designed — you can essentially do more with less lines of code.

Having known that you can do more with less, let us not forget that each language has its own benefits and drawbacks. Without going deep into technicality since this article is addressed to audience relatively new to programming, we must assume that Python is slow compared to other Object oriented languages and has implicit declaration of variables which can mess-up your code pretty quickly and make it hard for you to debug the application. Also Python is a modern high-level language, and hence it makes no sense to manually construct data structures or implement low-level threading on Python.

Most of the disadvantages are subsets or closely related to the above mentioned problems with Python. But if all of that hasn’t convinced you to sway away from using Python, then be prepared to  experience the awesome advantages!

1) Less code

Python programs are typically 3-5 times shorter than equivalent Java programs, and 5-10 times shorter than equivalent C/C++ programs! While the load on the Python interpreter is relatively high while executing a Python program, it all comes down to how willing one is to compromise simplicity with memory.

Most people in the industry prefer using Python as a prototyping language for rapid application development. Also, certain modules of a program which may seem too cumbersome to implement in the low-level languages can be written in Python to obtain a great combination of, let’s say, Java for the large part of the application and Python for the more complex calculation of data.

This slowness may only be experienced in large applications. If you think about writing a 100 line Python script to do something with web-scrapping or natural language processing, performance isn’t going to be an issue owing to the fact that most of our personal computers now have memory in terms of Gigabytes!

2) No compiling

You don’t need to compile your Python program to run it. Which also means there is no need for a compiler, or a virtual-machine, or any of those byte-code to native or vice-versa translations! All you got to do is create a file, for example, hello.py, and simply run it from the terminal. There are of course disadvantages to it, but hey, we need to take a side!

Also Read – Top 5 Free Android App Source Code Websites to Download Open Source Codes

3) Not good at data structures? Don’t worry about it!

Python has some really great data-types like dictionary, lists, tuples, easy-to-customize arrays, and more! While this makes things easier for a programmer, it also restricts the way you’d approach a design problem. But since these data-structures are built-in, they are highly optimized and general-purpose.

Unless you want to design some really specific data-types which can operate with a relatively higher speed specific to your application, Python will do most of the tedious job for you!

4) Massive amount of libraries

Python’s culture is unique in a way that its developer community values open source software, international events, and encouraging non-programmers to learn programming. Hence there are lots of libraries which you can use – from socket programming, desktop GUI toolkits, to data science, image processing, and what not! There is a library for almost everything in Python.

Most people in the Python community do not see programming simply as a means to program a computer – it is rather perceived as a way of solving problems in real life. No wonder, programming in any language helps you think better, but it’s just that Python makes it easier to take the first step.

This brings us to explore the fact that most Universities in the US choose python as the standard language for introductory-level programming classes; as opposed to C and C++ which are widely used in India to introduce programming to engineering and computer-application students. Some specific departments, for example, the iSchool at Berkeley encourage Python for MS and Ph.D. studies in Information Systems.

Should the Indian education system switch to Python instead of C/C++ for its introductory courses?

Absolutely! It is no secret that half of the IT or CE graduates from the mid-tier colleges (Non IITs and other top-tier colleges) have no interest in programming or whatsoever. Why do you think the on-campus recruiting companies visiting these mid-tier colleges need to make their students go through a rigorous training process? Because while most students may be excellent performers when it comes to understanding and applying the theoretical knowledge, only a few actually understand the subtleties of code so much as to discern between the good code and the bad code approach while developing an application.

It is certainly not a rule that Java and C++ are hard to understand, but to most people, a Python script is more readable and less intimidating. Here’s an example of the classic ‘Hello world’ application compared in C++, Java, and Python — all which follow the object-oriented paradigm.

C++:


#include <iostream.h>
void main()
{
cout << "Hello world" << endl;
}

Java:

Import .. //whatever you wish to import

public class HelloWorld{

public static void main(String args[]){

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

}

}

Python:

print “hello world”

#That’s it. A naive example, but really, that’s it.

As we can see, to teach programming to beginners, Python would be a clear winner for its simplicity. Whereas the same ‘hello world’ program in C++ and Java would mean explaining functions, import and include statements, parameters and arguments, scope, and more before getting to the System.out or cout statements, which again have their own sources of origin.

Of course, one may choose to skip all the explanation and verbosity and get to the point, but to the curious mind it is simply deleterious! One cannot imagine writing programs just for the sake of writing blindly. But what do the teachers in our system do? They simply ignore the nuances and get down to teaching the complexities which one can either contemplate over, or simply mug-up!

This hinders the process of creative thinking among the novice programming students and can make them quickly disinterested. These obscure syntax of Java and C++ may be enough for a beginner to lose interest in programming and look for alternatives.

For more information on why beginners should choose Python, do watch the video below where Jessica McKellar introduce the Python language:

Installing Python

Now that you seem to be really interested in starting to program with Python, here is how you begin. 

Windows

  • Visit https://www.python.org/downloads/windows/

python.org_windows

On the download page, you will be greeted with two versions of Python – 2.x.x and 3.x.x. So, which one should you go for? Python 2 or Python 3? Well, it turns out that it really depends on which libraries you want to use. If you are new to programming, Python 2.x is recommended since most online courses which we are going to include at the end of this article rely on Python 2.x version.

Also, most the Linux distros and OS X have Python 2.7.x as their default interpreter. So unless you’re explicitly trying to change this default or intend to use libraries specific and better supported for Python 3.x, we would recommend you go for the 2.x version.

python.org_windows_1

  • Next, you should see several download links at your disposal. Clicking on one of these download files can be very confusing for beginners, but most people will understand that Windows x86-64 MSI installer for the 64 bit processor computers, and Windows x86 MSI installer for the 32 bit computers is the correct choice in case of Windows Operating System.

python_install

  • Follow the on-screen instructions, and notice that the default folder of installation will be something like C:\Python27\

Once the installation is finished, you might want to access python interpreter from the command line without having to change the directory to Python27. To do that, we must add Python to our Windows Path which is also called adding Python environment variables to our system.

  • On your system properties, you will see something like above. Click on ‘Advanced system settings’

 

env_variables_windows

  • Upon clicking the Environment Variables, you should see something like this:

env_variables_windows_2

Double click on ‘Path’ and something similar to this should appear, depending on the programs installed on your computer.

env_variables_windows_3

  • Click on ‘New’ and copy paste the following lines, one at a time:C:\Python27\Lib 

C:\Python27\DLLs
C:\Python27\
C:\Python27\Lib\lib-tk

env_variables_windows_4
Once you have added these variables, exit the system properties and open a command line terminal by holding (windows-key) + R, and typing ‘cmd’ in the run box.

windows_run_cmd

  • Once the terminal has started, simply type python and hit enter

python_cmd_1

This is your python shell, where you can execute python commands line-by-line.

You can type: print “hello world” and see what happens.

python_cmd_2
8) Writing longer programs in python require you to use a text editor and execute the program file. In this example, we will use the Sublime text editor, but you could use notepad as well.

python_cmd_3

Just to be non-repetitive, let’s do some math. As you can see, in Python, it is pretty simple to declare variables and assign values to it. Save this file as “hello_world.py” in your preferred folder. For this example, we will save it on Desktop.

9) Next open the command line and navigate to Desktop as shown below.

python_cmd_4

Type hello_world.py and the program will execute without you having to navigate to the Python27 folder. This is because we have already added the Python27 folder to the windows PATH.

So that’s pretty much it. Now you can execute more complex programs in the same way. This is a bit different on LINUX and OS X.

LINUX

Python comes pre-installed on Linux. Use your favorite text editor and repeat the steps. You don’t need to add environment variable in the case of UNIX environment for Python. Type python hello_world.py

python_cmd_5
As you can see, the output is hello world. This means that our Python program was executed successfully. As one of the advantages/drawbacks (however you may take it) which we discussed in the starting of this article, Python is an interpreted language, and hence you don’t need to compile the .py files, just execute them directly.

Pretty neat isn’t it?

Learn more.

Here are a few resources where you can learn Python for free. It’s up to you which site best matches your approach, since learning Python for courses designed for, let’s say, data science, game design, and functional programming, will need you to approach problems in distinct ways.

1) Python For Everybody – Coursera.com

Python_For_Everybody_Coursera

This free online course is available mostly thought-out the year, and its certificate is available for purchase. You can also opt for a specialization in informatics as a part of this course, which includes a capstone project. Visit https://www.coursera.org/learn/python

2) Python on codeacademy.com

Python_Code_Academy

This course should give you a hands-on approach into learning the rudimentary concepts of python, ranging from writing for-loops to file IO operations and classes in Python. The course is free, and comes with a paid final project.

3) Google’s Python Class

Google_Python_Class

If you would like to learn python by referring to docs, then this is the best place! While this may seem to be really hard for people who are looking for a teacher, you can learn quickly referring to these docs.

Visit https://developers.google.com/edu/python/

4) Learn Python the Hard Way

Python_Hard_Way

If you are up for spending about $29.5, then this course will provide you with videos and other material which should get you going with Python. As the site claims, the course is also as appealing to people who have no experience in programming.

The book, however, is available for free at http://learnpythonthehardway.org/book

Visit the full site at: http://learnpythonthehardway.org/

Conclusion

While Python programming may seem appealing, it is up-to an individual about how far they would like to go. Some people are content with the basic knowledge of programming, while others go on to make complex web applications and face recognition systems on Python.

No wonder what your career goal is, knowing the basics of programming – that too on a language so simple and elegant; will always help you apply your logic better in real world situations, and life itself.

Just like the famous Rapper Will.i.am said in 2013, “Coding, by about 10 times, a trillion times, is the most creative space.” — read the full interview here

Happy coding!

Continue Reading

Vishal vatnani is a student who love exploring new programming languages. He writes about technology and programming languages and will keep sharing his experience with others.

Click to comment
To Top