Wednesday, January 3, 2018

First python script

Open an editor with first.py

type below lines

print("hi")

print("jith")

Now run it in terminal,

JITSUNDA-M-C2XF:~ jitsunda$ python3 first.py
hi
jith

JITSUNDA-M-C2XF:~ jitsunda$ 

Python interactive mode - REPL

Read–Eval–Print Loop (REPL) is an interactive language shell or interactive computer programming environment. The advantage of having REPL is that the environment receives input from user, evaluates and results in an interactive manner. No need for scripting.


JITSUNDA-M-C2XF:~ jitsunda$ python3
Python 3.6.3 (default, Oct  4 2017, 06:09:15) 
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

>>> 

I use python3, 

Simply type python3, we will get ">>>" prompt, we can write simple instructions and get the results as shown below



JITSUNDA-M-C2XF:~ jitsunda$ python3
Python 3.6.3 (default, Oct  4 2017, 06:09:15) 
[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print("hi")
hi
>>> 4+3
7
>>> x = "jith"
>>> x
'jith'

>>> 

Intro to Python

Introduction to Python

Python is a computer language similar to C, C++, Java, C# etc .. However there are lot of features in python make it unique compare to other languages. Especially, the unprecedented growth of data science and machine learning is making Python as most popular language at present. This is due to the flexibility and computational friendly nature of Python.

Advantages of Python

Very high level language, so we can prototype rapidly an idea or an algorithm
Object oriented programming, Interpreted, Interactive and Portable
It can interact with C and C++ well (Extensibility feature of Python)
Large set of packages
Easy integration
Apt for scientific computing
Dynamically typed

Limitations of Python

In my opinion, Still it is considered as glue language or just scripting language or language for automating tasks in industry rather than being used as a main-stream language such as Java, C#, C etc ..
Slow compare to C