Python @ DjangoSpin

Why choose Python?

Buffer this pageShare on FacebookPrint this pageTweet about this on TwitterShare on Google+Share on LinkedInShare on StumbleUpon
Reading Time: 6 minutes

Why choose Python?

Why choose Python?

If you are wondering why to learn Python, well, here's why:

  • Easiest-to-learn & Most-enjoyable-to-use: Python is arguably the easiest-to-learn programming language, and the most enjoyable to use.
  • Powerful: Python has all the power you'd expect from a modern programming language. By the end of this course, you'll learn how to process files, how to employ a variety of data structures. If you choose to opt for creating a graphical user interface for your program, you could do that as well. You could create an online blog using Django, create a 2D game with PyGame, create a visual novel, carry out web scraping etc.
  • Main Emphasis: The main emphasis of Python is readability, reusability & maintainability of code and enhancing productivity. We will see this as we proceed further.
  • General-purpose nature: Being a general purpose language implies allowing its user to write software in a wide variety of application domains. You could automate a simple task of mailing yourself a file on your desktop every Thursday at 9 pm, or you could create a visual novel with it, pursue GUI development, make web apps with it, make a blog with Django, so on and so forth.
  • Used frequently to glue projects together: It has bindings for C/C++ and Java so it is common to blend large projects together using interfaces built in Python.
  • Interactivity: Python can be used interactively in the command line to execute one statement at a time. It also comes with IDLE, its own text editor which has an inbuilt interpreter, where you can execute commands one by one, and view the result immediately. The interactivity enables us to create scripts in a flash, which can be used for rapid prototyping. Prototyping, in programming terms is a rough draft of the final product that companies deliver to their customers, with limited features and core functionality intact. Python can also be used in a realtime interpreter for testing code snippets before adding bundling into an executable file.
  • No braces and semi-colons: One of the most popular characteristics of Python is its use of white space to differentiate between statements. Although it is not a genuine reason for anyone to learn Python, but people who have experience with Java, C++, C# will find it a pleasant change to work without braces and semi-colons. Braces in these languages are used to separate blocks of code, and semi-colons are statement delimiters, i.e. to create a barrier between consecutive statements. Python uses indentation for separating blocks of code and carriage return as statement delimiter. This feature has been derived from the language ABC, from which Python itself was largely derived.
  • Cross-platform: Python can be run on Windows and Unix-like systems all the same.
  • It is a Scripting Language: Meaning that it’s not compiled to create the machine-readable code, like a programming language called C++.
  • Enjoyment: Due of Python’s ease of use and built-in toolset, programming can seem like pleasure rather than a tedious chore. Although this may not sound very convincing, it does have a significant impact on the productivity.
  • High Level Language: Now, what that means is that it takes care of a lot of things that will usually throw off a beginner. According to Wikipedia, "In computer science, a high-level programming language is a programming language with strong abstraction from the details of the computer. In comparison to low-level programming languages, it may use natural language elements, be easier to use, or may automate (or even hide entirely) significant areas of computing systems (e.g. memory management), making the process of developing a program simpler and more understandable relative to a lower-level language." "There are three general modes of execution for modern high-level languages: compiled, interpreted, trans-compiled." We have briefly discussed the first two, with C++ being a compiled language, and Python being an interpreted language. The third kind simply means that the code is translated to another language that is much more widely used, like C.
  • Dynamic Typing/Duck Typing: Python is a dynamic-typed or duck-typed language. Many other languages, like C++, Java etc. are static typed. Meaning that they require the programmer to explicitly mention what type of data each variable is. For beginners, variables are containers for different values that are used in the program. For example, name of a person is of type string (combination of characters), and his age is of type integer. In static typing, you explicitly mention that the variable name is of type string, whereas dynamic typing indicates that if a variable behaves like a string, it is a string, and we need not mention it that it is a string. The reason it is also called duck typing, is that it refers to the duct test, which is attributed to Mr James Whitcomb Riley, and it is as follows "When I see a bird that walks like a duck and swims like a duck and quacks like a duck, I call that bird a duck." If this doesn't make sense to you right now, it will in time, when we dive into the language.
  • Fairly small keywords list: Keywords are reserved words, they have special meaning in the language. Python has the following keywords:
    False     class     finally     is     return
    None    continue    for    lambda    try
    True     def     from    nonlocal    while
    and       del       global       not       with
    as         elif          if          or          yield
    assert    else    import    pass    break
    except    in    raise
  • Choice of paradigm: Procedural & Object-oriented Programming: Do not be put off by these terms, they only look ponderous. Procedural Programming paradigm suggests a step-by-step process of a developing program, calling procedures/functions/methods/subroutines to perform some processing, then control returns back to the main program. Examples of procedural languages are C and BASIC.
    Object-Oriented Programming (OOP) paradigm deals with making classes. A Class is a prototype of similar objects e.g. a car is a class and Mercedes and BMW are its objects. Each class will have variables and methods (that's what they call functions in this OOP terms) which each of its objects will inherit e.g. variables(properties/attributes) of a car could be its engine power, its top speed, and methods could be ignite(which triggers the ignition of the car) brake, accelerate. Aside from these, the objects can have variables and methods of their own, which are characteristic of these objects only e.g one object may have airbag method, whereas another object may have spoiler variable. I hope you get the gist. I have only scratched the surface here, if you are interested in OOPs, you could try googling it a bit, it is an extremely widely used paradigm. We, at djangoSpin, have a course on Object Oriented Python.
    Python employs both of these paradigms, it in fact offers a choice to the developer, whether to tackle a program step-by-step using functions or creating classes to achieve the same. You could start with procedural approach, which is much easier in my view. Then you could move onto OOP, which can be daunting at first, but Python is a great language to get to grips with the OOP paradigm. Object Oriented programming is widely acclaimed for developing large projects. In this course, we will be following the procedural way of programming.
  • Many lines of interest: You could develop 2D games with PyGame library, you could take up GUI development with Tkinter & PyQT, choose to make web apps with frameworks like Flask, Django etc.
  • Extensive Standard Library: One of Python’s great attributes is that it comes with an extensive standard library — this enables us to do tasks like download an image or any file for that matter from the Internet, start a web server, or manipulate a compressed archive file all with just one or a few lines of code.
  • Strong Community: Python has a huge and strong community. Not only does it have a dedicated newsgroup, but it also has Python Tutor mailing list, especially for beginners. It is located at http://mail.python.org/mailman/listinfo/tutor. The mailing list is not limited to beginners, anyone can ask questions here. Something that is evident is that the community by and large is extremely open and friendly, just like the language is user-friendly.
  • Versatility: Generally speaking, all languages are versatile, but its bindings to C, its readability, its general-purpose nature, wide community, list of libraries available, and a very good development team led by Guido van Rossum, all this makes Python versatile.
  • Well-paid jobs: Python jobs are generally very well-paid. In fact it is one Google's recruiting tactics to see if a person is googling Python terms frequently, and if he is, he may even receive a call from Google, just like this guy here.
  • It is open source: Not only is Python free, but Python's license allows you to even modify it and resell it. By allowing this freedom, Python has epitomized the ideals of open source software and this is one of the many reasons that Python is so popular.
  • Succinctness: One of the features that attracted me towards Python was that you could get a lot done in a few lines of code, as compared to many other languages. Programming languages like Java, C, C# are verbose, but Python is succinct. For example, here's a program in C, C#, Java and Python to achieve the same purpose.
  • /* C Program to generate Fibonacci Series*/
    
    #include <stdio.h>
    
    int main() {
      int n, number1 = 0, number2 = 1, next, c;
      printf("Enter the number of terms\n");
      scanf("%d",&n);
      printf("First %d terms of Fibonacci series are :-\n",n);
    
      for ( c = 0 ; c < n ; c++ ) {
        if ( c <= 1 )
          next = c;
        else {
          next = number1 + number2;
          number1 = number2;
          number2 = next;
        }
        printf("%d\n",next);
      }
    
      return 0;
    }
    
    /* C# program to generate Fibonacci Series */
    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace fibonacci {
     class Program {
     static void Main(string[] args) {
     int i, count, number1 = 0, number2 = 1, number3 = 0;
     Console.Write("Enter the number of fibonacci numbers: ");
     count = int.Parse(Console.ReadLine());
     Console.WriteLine(number1);
     Console.WriteLine(number2);
     
     for (i = 0; i <= count; i++) {
     number3 = number1 + number2;
     Console.WriteLine(number3);
     number1 = number2;
     number2 = number3;
     }
     Console.ReadLine();
     }
     }
    }
    // Java Program to generate Fibonacci Series
    
    class Fibonacci {
        public static void main(String args[]){
          int number1=0,number2=1,number3,i,count=10;
          System.out.print(number1+" "+number2);
    
          for(i = 2; i < count; ++i) {
            number3 = number1 + number2;
            System.out.print(" " + number3);
            number1 = number2;
            number2 = number3;
          }
       }
    }
    
    # Python program to generate Fibonacci Series
    
    def fib(n):
        a, b = 0, 1
            while a < n:
                print(a, end=' ')
                a, b = b, a+b
                print()
    
    fib(1000)
    

All these features of this language, not only do they make Python a great first language to learn, but it has also lured a lot of high-level programmers.


See also:

Buffer this pageShare on FacebookPrint this pageTweet about this on TwitterShare on Google+Share on LinkedInShare on StumbleUpon

Leave a Reply