1. Introduction to Python

Python is one of the most popular and fastest growing programming language which is being used by many professionals such as Data Analysts, Data Scientist, Scientists, Accountants, Mathematicians, Software Engineers, Network Engineers and so on. Python is being used in various fields such as data analysis, machine learning, artificial intelligence, big data, Automation, development of web and mobile apps, testing, hacking and so on.

2. Features of Python

1. Easy: Python is easy to learn and understand

2. Expressive : Python was designed to be highly readable which uses English keywords frequently where as other languages use punctuation and it has fewer syntactical constructions than other languages.

3. Free and Open Source : Python is free and open source

4. High-Level : Python is a high level programming language

5. Portable : Python program written on one platform (Windows, Linux, Mac) can be executed on another platform without requiring to change any code.

6. Object Oriented : Python supports object oriented concepts

7. Extensible : Python modules can be written in other programming languages such as C, C++ etc.

8. Embeddable : Python is preferred in embedded system as it is simple and requires less coding

9. Interpreted and Interactive : Python programs are processed at run time by the interpreter, no need to compile the program before executing it. Python is also considered as interactive because using the python prompt we can interact with the interpreter directly to write programs.

10. Large Standard Library : Python has huge number of libraries

11. GUI Programming : Python provides libraries using which one can develop GUI applications

12. Dynamically Typed : User need not to worry about the data type as python will identify and set the data type. For example if you declare a=10 then a will be considered as an integer and if you declare a=10.0 then a will be considered as float.

In [1]:
a=10
print(type(a))
a=10.0
print(type(a))
<class 'int'>
<class 'float'>

3. Java vs Python

Parameter Java Python
Compilation Java is a Compiled Language Python is an Interpreted Language
Static or Dynamic Java is statically typed Python is dynamically typed
String operations Offers limited string related functions It offers lots of string related functions
Learning curve Complex learning curve Easy to learn and use
Multiple inheritances Multiple inheritances is partially done through interfaces It offers both single and multiple inheritances
Braces vs. Indentation It uses curly braces to define the beginning and end of each function and class definition Python uses indentation to separate code into code blocks
Portability Any computer or mobile device which is able to run the Java virtual machine can run a Java application Python programs need an interpreter installed on the target machine to translate Python code. Compared to Java, Python is less portable
Best use for Java is best for Desktop GUI apps, Embed Systems, Web application services, etc Python is excellent for scientific and numeric computing, Machine learning apps, more
Database support Java offers stable connectivity Python offers weak connectivity

Disadvantages of Java

  1. JIT (Just In Time) compiler makes the program comparatively slow.
  2. Java has high memory and processing requirements. Therefore, hardware cost increases.
  3. It does not provide support for low-level programming constructs like pointers.
  4. You don't have any control over garbage collection as Java does not offer functions like delete( ), free( ).

Disadvantages of Python

  1. Used in fewer platforms.
  2. Python is interpreted, so it's much slower than its counterparts.
  3. Weak in mobile computing, hence not used in app development
  4. Since Python is dynamic, more errors show up at run-time
  5. Absence of commercial support

4. Comments in python

Writing comments in a program helps in understanding the program better as it provides the documnetation. Every programming language has its own syntax for identifying what is a comment. Any line which is commented will not be executed by the compiler. In python, a line could be converted to a comment by using either # symbol or write the statements within tripple quotes(either single tripple quote ''' some text ''' or double tripple quote """ some text """).

In [2]:
# This line is commented and won’t be executed

''' This would be a multiline comment
in Python that spans several lines and
describes your code, your day, or anything you want it to '''
Out[2]:
' This would be a multiline comment\nin Python that spans several lines and\ndescribes your code, your day, or anything you want it to '
In [3]:
""" This would be a multiline comment 
in Python that spans several lines and
describes your code, your day, or anything you want it to """
Out[3]:
' This would be a multiline comment \nin Python that spans several lines and\ndescribes your code, your day, or anything you want it to '
__Please note:__ The recommended method for commenting multiple lines is using \# on each line. The use of tripple quote method isn’t actually a comment but defines a Text constant of the text between the tripple quote. It isn’t displayed, but exists and could potentially cause unexpected errors.
In [4]:
#a2=10
print(a2) # This will generate NameError as the first line is commented
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-4-025c518dab64> in <module>
      1 #a2=10
----> 2 print(a2) # This will generate NameError as the first line is commented

NameError: name 'a2' is not defined