Friday, June 30, 2017

Learn Programming in Python in 20 days - Day 1 - Introduction

This is first article for a 20 article series to help you learn programming from scratch. The series assumes basic familiarity with programming jargons. 

This is the introduction for learning Python programming language. This is also based on the assumption that Python is easy to learn and get going with. One of the prime reasons for this is that that Python is relatively new language -Fortran (1957), C ( 1972)  , C++ (1980), Python (1991) , Java , JavaScript ,PHP (1995) , C# (2001) and so on ... To set it in correct perspective having worked on all of these languages mentioned above, the journey for learning Python will also be like a exploration to me where I will also like to relate how the same thing was done in other Programming language.

This lecture will cover only the installation of Python language on your machines : 
  1.  Check if Python is already present on your machine by typing python on command prompt. If you see version number of Python installed emitted from the Python interpreter  than we are good to go 
  2. Download python from link here for appropriate release.  For these lecture series I will be using Python 2.7 though. Download the msi file and install it. For Linux install Python 2.X and Python 2.X Dev Packages
  3. Once done installing  type Python on the command prompt. Good to go ? 

Compiled vs Interpreted Language

  • A basic difference between languages like C# , Java and Python is they are complied before the execution of the program. A compiler is a program that understand the code line by line , decodes each and every declaration before hand - variables and function calls , types of variable - Integer , characters etc. and operators to generate the machine readable code i.e. the code gets optimized for that particular machine set before execution. 
  • For Interpreted languages on the other hand there is a another program - Interpreter that executes the code flow at run time i.e. when the program is run the interpreter  converts the code in machine readable format.
  • The benefit is we need not to compile the program every time we intend to run it and therefore the deployment becomes quite easy when compared to complied languages like Java. Each time we change a function in Java Application the whole application is rebuilt leading to down time of the service whereas in Python the same can be achieved by just changing the function and saving the file , the next time the code is executed the interpreter picks up a fresh piece of code

Using Variables

  • With the above in mind lets talk about the variables in a Program - a variable is used when we want to assign or store certain value within our program. A variable can be of many type - Integer ( 1,2,100 etc.) , Floats / Doubles ( 1.2, 200.22456) , characters ( A, $, b etc.) , string ("what an awesome weather"). Although character as a Type is not present in Python its available in other native languages.
  •  For Python character is nothing but string of size one. Python Interpreter understand the type of variable and stores it in appropriate type.
  • So while we have only one function to add two variables in Python , in C# or Java there will be multiple functions to add two strings as we need to define the type of variable before hand
  • Variables are the way to think about a program - suppose we want a program that gives full name of a person as output. What will we need to have full name - First Name , Middle Name & Last Name. 
  • So lets store them as variables - vFirstName , vMiddleName , vLastName. The output also we need to store somewhere say vFullName. Our program ( Any language of choice ) now will take 3 inputs and return one output by operating on them - vFullName = vFirstName+vMiddleName+vLastName.  And let the program return the vFullName as final output.
  • Tip - Try to break the problem in parts , try to think what all input we need , what kind of processing one needs to do and how to get  the output
Post your problems in the comments below. I will try and answer you back. 

No comments:

Post a Comment