May 15, 2020

Python for Java Developers

python java

Python was named for the BBC TV show Monty Python’s Flying Circus. The code was first published by Guido van Rossum in February 1991. Already present at this stage in development were classes with inheritance, exception handling, functions, and the core datatypes. Also in this initial release was a module system and exception handling borrowed from Modula-3.
Python 3.8 was released on October 14th, 2019 with Assignment expressions.

everything in Python is an object.

Executing a python program

To run a python program in interpreted mode you need to create a textfile main.py with the content

  print("Hello World!")

it can be executed by a python interpreter with the command

  python main.py

To run python code in a interpreter in interactive Mode, you need to first start the interpreter with python then enter print("Hello World!")

To create a batchfile to be executed in the python interpreter:

  #!/bin/python

  print("Hello World!")

Syntax

Reserved words

You can not use a reserved word as a user-defined identifier. The following is a list of reserved words in Python:

  and     assert    break     class     continue
  def     del       elif      else      except
  exec    finally   for       from      global
  if      import    in        is        lambda
  not     or        pass      print     raise

Comments

A comment in Python starts with the hash character, ´´#´´, and extends to the end of the line. Python doesn’t have explicit support for multi-line comments, you either combine multiple single line comments or use a docstring which is intended to create documentation from code. A docstring is enclosed in triple quotation marks (´´"""´´) it is used to auto generate documentation which should be contained in the sourcecode.

Datatypes

Variables do not have a type and can store a reference to any type of object,

Objects

The constructor of a Python class is defined using the special name init. A class may only contain a single constructor. To provide multiple constructor options, you must use default values as was done in the Point class example or use inheritance to create a new derived class with a new constructor.