Python Object-Oriented Programming(OOP)

python oop

Python OOP

In this article we will go through the Python OOP Concepts. OOP is termed as Object Oriented Programming and it is distinguished based on various concepts such as objects, class and methods etc. There is one more type of language exists called as
Procedural Oriented Programing language(POP). You probably heard that most of
the expert started their career with C- language and this is a procedural Oriented Programming. 

There are many limitations and complexity with POP hence the new concept originated – Object Oriented Programming language(OOP) with its various useful features. OOP languages are very famous and used in almost all existing popular languages, also it is getting considered for new languages which are currently under development. 

The major need for developing such languages was to manage the ever-increasing size and complexity of programs.

Now question is, why OOP languages are so popular and why everybody liked to acquire those concepts. You will get to know in-and-out about OOPs features in this article – stay tuned!!

Python is an Object-Oriented Programming Language and here we will discuss OOPs concept by taking reference of simple python programs. Don’t worry, if you do not know Python.  It is not necessary to know python in advance to understand OOPs concept in general or OPPs with Python.

PYTHON OOP : Basic Concept

Any complex language starts with the simple concept irrespective of complexities
involved in that areas. There are few simple python OOP features but it is base of python programming models.

Python OOP features

1.  Class

2.     Object

3.     Abstraction

4.     Polymorphism

5.     Inheritance

6.     Encapsulation

Class

In simple
way, class is a grouping of data and its associated functions. Once a class has
been defined, we can create any number of objects associated with that class.

For example, Account_Number, Balance, Credit() and Debit() are the member of Class Bank. If Bank has been defined as a class, then the statement Bank-Balance , will create an object Balance belonging to the class Bank.

[table id=6 /]

Object

Object is an
instance of a class. In other words, Object is a way to access features of a
class. As described above a class contains the associated data and its function
but to access its features Objects play major role. 

Consider class
– Bank from above example and try to understand the power of object. You
already have defined class- Bank with associated data and functions to perform
credit and debit operations. The normal operation happening in bank system is
account holder debit some money from account or credit some money into account. 

Assume,
customer 1 has defined cust1 as an object of class Bank and customer 2 has
defined cust2 as an object of same class Bank.

Let’s try to credit some amount into customer 1’s account and debit some amount from customer 2’s account by accessing features of Class Bank through objects cust1 and cust2 respectively.

 
# Credit 1000 in customer-1 account
cust1.credit(1000)
# Debit 500 from customer-2 account
cust2.debit(500)

Abstraction

An abstraction is very important aspect to hide complexity or internal background
processes and represent essential features. To understand this concept more
clearly, take the same example of class Bank. 

In first two points, we have already seen credit and debit example while describing class and object. Observe those examples, you are just calling function by pointing
out correct class object with value. In this process you need not to know what is
happening inside when you are calling credit or debit functions. How and What process happening inside is hidden from you. 

This is
abstraction, where you only know the essential things to operate on banking
system without knowing the background details of actual complex calculations.

It gives flexibility
and simplicity to the users to use complex application knowing minimal required
things to operate on.

Polymorphism

In simple
words, A single function name can be used to handle different operations by
passing necessary arguments. This is something similar to a particular word
having several different meanings depending upon the context. 

For example,
you have a class shape, and you have to draw the shapes. But they draw
differently. Here, the “draw” behavior is polymorphic in the sense
and depends on the shape. So, the abstract “shape” concept does not
actually “draw”, but specific shapes (like circle or rectangle) have
a concrete implementation of the action “draw”.

PS-Function overloading is not supported in Python OOP.

Polymorphism
plays an important role in allowing objects having different internal
structures to share the same external interface. Polymorphism is extensively
used in implementing inheritance.

Inheritance

Inheritance
is the process of creating new class based on an existing class. In other words,
it is the process by which objects of one class acquired the properties of
objects of another classes. It supports the concept of hierarchical
classification.

The one whose properties are acquired is known as a base class or parent class and the new class is known as a derived class or child class.

Inheritance can be easily described with class computer. In the computer class we have defined all its accessories and features. Another class created for – Laptop by
inheriting its properties from class computer. In this case, Computer is the base or parent class and Laptop is the derived or child class.

Encapsulation

Encapsulation
is also an important feature of object-oriented programming language. The
wrapping up of data and function into a single unit (called class) known as
encapsulation. If you are creating class, you are doing encapsulation.

The data abstraction and encapsulation go hand-in-hand. An abstraction is used to hide internal details and show only functionalities, it can be only achieved through
encapsulation.

Photo Credits: Pixeles

Python try except and finally

Python try except and finally - exceptional handling

An exception is a very known to every programmer! Afterall we most of the time seems to be playing with this keyword. Python try except and finally statements allow you to handle these exceptions.

Python exception or error doesn’t indicate that there is always something wrong with the logic or algorithm. 

There are some circumstances where your program is absolutely correct, still you encounter run-time error that situation is known as an EXCEPTION.

At this point, our run time errors resulted in a termination of program execution. Rather terminating the program execution, program could detect the error before hand and handle it in a very smart way, that concept is called as Exceptional handling.

An Exceptional handling is a standard python mechanism allows programmers to deal with the run-time errors. 

Examples of exceptional errors: integer division by zero, attempting to convert a non-number to an integer, accessing a list with an out-of-range index, and using an object reference set to None.

Few common python exceptions are described here but if you want to go through all the exception list then visit this page Python built-in Exception.

PYTHON EXCEPTIONS

1. ZeroDivisionError: division by zero

You have a program where you are doing some calculations. You have defined two integer variables and assigned value to them. Now you are trying to attempt division operation.

N1=int(input(“Enter first Number – N1 :”))

N2=int(input(“Enter Second Number – N2 :”))

Result=N1/N2

print(“Result :”, Result)

Your code is absolutely perfect, and it will give you division answer but what will happen if user enters 0 value for variable N2! Always remember, you never have a control over an end user. 

In this case program execution will be terminated with error – ZeroDivisionError: division by zero

Output

Enter first Number – N1 :100

Enter Second Number – N2 :0

Traceback (most recent call last):

File “C:/Users/Python37/exceptional_handling.py”, line 3, in

Result=N1/N2

ZeroDivisionError: division by zero

>>>

2. ValueError: invalid
literal for int()

To continues with same above example where you expect user should enter integer number(digits) but consider user has entered some random characters or numbers in a word (say five instead of 5) for variable N1 then WHAT? It will throw this exception – ValueError: invalid literal for int()

Enter first Number – N1 :five

Traceback (most recent call last):

  File “C:/Users/Python37/exceptional_handling.py”, line 1, in <module>

    N1=int(input(“Enter first Number – N1 :”))

ValueError: invalid literal for int() with base 10: ‘five’

>>> 

3. OverflowError:
integer division result too large for a float

To continues with the same example, now user has entered very large number for variable N1. Observe what happened with your result – error  OverflowError: integer division result too large for a float

python exception handling OverflowError

Looking for Solution?

Yes, it is absolutely possible to write a code to avoid such kind of errors in python like other programming languages, but python has unique features which you can apply.

Python has built in conditional execution structure to handle the situation where you might encounter expected or unexpected run-time errors.

1.    Try

2.    Except

3.    Else

4.    Finally

Python Try and except

try/except block to be added where you think potential exception can occur in your program. 

Syntax:

try:

                  #It contains code that might raise an exception.

except:

                  #It contains code to execute Only when try block raise an exception.

Back to our previous example and we will see how it works. Now you know where possible exception error can come in our example so try to add try/except block into it.

Firstly, we will try display text message to the user so they can understand what went wrong! The technical error user might not understand so let’s change default error message with simple plain English text.

try:

    N1=int(input(“Enter first Number – N1 :”))

    N2=int(input(“Enter Second Number – N2 :”))

    Result=N1/N2

    print(“Result :”, Result)

except ValueError:

    print(“Oops!! Seems you have entered invalid Number”)

except OverflowError:

    print(“Oops-ERROR!! Result value seems to be too large to display”)

print(“Program execution continues….”)

Scenario #1

Enter first Number – N1 :five

Oops!! Seems you have entered invalid Number

Program execution continues….

>>> 

Scenario #2

python try except exception handling

Summary

  • Program execution doesn’t terminate when you use try except block and exception occurs.
  • An except block doesn’t execute unless try block don’t raise an exception.
  • Multiple except block can be written for one try block.

Python else

If try block raise an exception, then only except block gets executed otherwise else block will be executed.

In other words, else block only executed when try block do not raise an exception.

try:

    N1=int(input(“Enter first Number – N1 :”))

    N2=int(input(“Enter Second Number – N2 :”))

    Result=N1/N2

    print(“Result :”, Result)

except ValueError:

    print(“Oops!! Seems you have entered invalid Number”)

else:

print(“Division Successful!”)

print(“Program execution continues….”)

Python finally

finally block always executes after try/except block execution. It does nothing extraordinary, just creates the space for you to execute something after try/except block.

try:

    N1=int(input(“Enter first Number – N1 :”))

    N2=int(input(“Enter Second Number – N2 :”))

    Result=N1/N2

    print(“Result :”, Result)

except ValueError:

    print(“Oops!! Seems you have entered invalid Number”)

finally:

print(“Executing finally…block!”)

print(“Program execution continues….”)

So far, we have seen basic use of try/except, else and finally block in python. Mostly it is being used with the conditional loop statements and allow users to try one more time – with proper message on screen when they enter wrong values, for instance.

Example

Write a program to demonstrate an
exceptional handling case with Loop statements!

In this example users can input any small integer value less than 100. They can enter number greater than 100 to complete the program execution. This code will not fail or terminate the execution if try block raise ValueError exception.

x = 0

while x < 100:

    try:

    # I hope the user enters a valid Python integer!

        x = int(input(“Please enter small integer Number: “))

        print(“x =”, x)

    except ValueError:

        print(“Oops!! Input cannot be parsed as an integer – Please try again”)

print(“Program finished”)

 

Output

Please enter small integer Number: 25

x = 25

Please enter small integer Number: 50

x = 50

Please enter small integer Number: five

Oops!! Input cannot be parsed as an integer – Please try again

Please enter small integer Number: 5

x = 5

Please enter small integer Number: 200

x = 200

Program finished

>>> 

 

Read More: Python raise Keyword

Python raise keyword

python raise keyword

Python raise keyword. In python we can raise exception by using raise keyword. We have already gone through detailed overview on in-built Python exceptions and how it is being handled with python try except & finally statements.

All these exceptions are default and python interpreter decide when to raise the exception but WHAT if you want to raise an exception?

Python raise

Python gives your flexibility to raise exception whenever you want in the program. It is very powerful keyword and having unique features in it.

Mostly people are using python raise – keyword in conditional block to decide when and where to raise an exception.

Syntax:

raise  <exception>

When you specify raise keyword in your code and the moment program execution reaches that point – immediately exception is being raised by skipping further statements. 

An interpreter doesn’t see, whether do you really have an error in your code or not. It simply raises an exception as per specified exception name.

Example

Python_raise.py

var=10

print(“Var= “, var)

raise ValueError 

print(“Program execution continues….”)

Output:

Var=  10

Traceback (most recent call last):

  File “C:/Users/Documents/Python_raise.py”, line 3, in <module>

    raise ValueError

ValueError

>>> 

Python raise keyword most often used in try block for various reasons for instance, to cross verify whether exceptions are properly getting raised and check its execution flow, to avoid the program execution termination, etc.

python_raise.py

try:

    var=10

    print(“Var= “, var)

    raise ValueError

except ValueError:

    print(“Oops!! Value error raised “)  

print(“Program execution continues….”)

 

Output

Var=  10

Oops!! Value error raised

Program execution continues….

Use raise keyword in try except

It is very effective way to check whether your exceptional handling code – try/except block working properly without involving end user. 

If there would be chances of an exception can occur in your code where you already applied, try/except blocks but you want to test it then you can add raise keyword there.

Observe this example – We are performing division of two numbers by taking inputs from users.

In this case we know ValueError exception can occur if user enter non-digit number. We have already seen this example here.

Now we could test this exception by raising ValueError exception manually in the code, irrespective of user inputs. 

Python_raise.py

try:

    N1=int(input(“Enter first Number – N1 :”))

    N2=int(input(“Enter Second Number – N2 :”))

    Result=N1/N2

    print(“Result :”, Result)

    raise ValueError

except ValueError:

    print(“Oops!! Seems you have entered invalid Number”)

print(“Program execution continues….”)

Note this result – we have entered correct input values still ValueError exception encountered due to raise keyword specified in try block code.

Output

Enter first Number – N1 :100

Enter Second Number – N2 :12

Result : 8.333333333333334

Oops!! Seems you have entered invalid Number

Program execution continues….

>>> 

 

Read More: Python try except and finally

Python IF ELSE & Nested IF-ELSE Control Flow Statements

Python IF ELSE and Nested IF ELSE control flow statements

In this article we are going through Python IF ELSE control flow statements. It is almost same as other programming language such as C, C++ or java etc.

The program default executes sequentially but sometimes you have to take control on program execution to get the desired output. To control the program execution, we have special utilities or statements called as “Control flow statements” 

Control
Flow IF-ELSE Statements:

               1. IF-ELSE

               2. Nested IF-ELSE

1. Python IF ELSE

IF-ELSE statement used to evaluate the condition and executes the block of statements based on results which is either YES (true) or NO (false)

General Syntax:

If (Condition)

Statement(s)

Else

Statement(s)

Syntax in Python: 

It is bit different syntax in python to write IF-ELSE conditional control flow statements. A blank spaces (indentation) is very important factor while writing code in python, especially if-else or nested if-else multiple conditional blocks. One extra blank space can kill your program!

if:

            <statement(s)>

else:

            <statement(s)>

Note: Please make a note, if-else statements are in lower case characters. In case if you write it in upper case, then you will get syntax error which is most common mistake people are doing. Python is very case sensitive language! 

Example:

Python IF ELSE Statement code

Output:

Python IF ELSE Statement code output

2. Nested IF ELSE

Simple IF-ELSE works fine but if you have multiple conditions and each one of them depends on another condition then Nested If-ELSE is very useful and effective.

It gives you flexibility to write multiple conditions and control your set of commands. It also helps to minimize the execution time as if one condition is true then it will skip further conditions and saves the time.

Syntax:

if :

            <statement(s)>

elif :

            <statement(s)>

elif :

            <statement(s)>

else:

            <statement(s)>

Be careful with if-elif-else statements, they must appear as-is in lower case and ELSE IF should be elif only. In case if you write any character in uppercase or elseif instead of elif, then you will defintely gets syntax error. Python is very case sensitive language and doesn’t allow any syntax violation.

Example:

Python Nested IF ELSE Statement code
Python Nested IF ELSE Statement output

Read More: Python For Loop and While Loop

Python Interactive and Script Mode programming

PYTHON INTERACTIVE AND SCRIPT MODE PROGRAMMING

How to run Python Code?

There are two python programming modes you can use to submit your python programs, Python Interactive and Script Mode Programming.

 

An interpreter works in a same way for both the programming methods so ultimately, we get the same result. But there are few exceptions and limitations to use these methods.

 

If you still do not have python installed on your machine then what are you waiting for! Download Now!!

 

Python Programming modes:


1. Interactive Mode Python Programming

If you are using Command Prompt to write and execute python commands, then you must invoke the interpreter without any parameters. All you need to do is – write “python” and python prompt will start automatically.

Microsoft Windows [Version 10.0.17763.195]

(c) 2018 Microsoft Corporation. Med enerett.

 

H:>python

Python 3.7.2rc1 (tags/v3.7.2rc1:75a402a217, Dec 11 2018, 23:05:39) [MSC v.1916 64 bit (AMD64)] on win32

Type “help”, “copyright”, “credits” or “license” for more information.

>>> 

Type following command in your python prompt and press enter to see the result. The result will appear in next line automatically when you press ENTER.

>>> print(“This is a sample Python Program”) 

Result –

This is a sample Python Program

2. Script mode Python Programming

 

If you are using command prompt to execute python script, then you must invoke the interpreter with file name as parameter. You may write your python code in any editors – notepad, notepad++ but the file extension should be .py to execute the program by interpreter.

Let’s take same example and try to execute it in script mode. Your script name is blog.py and it has the same code –

 

print(“This is a sample Python Program”)

 

We assume that you have Python interpreter set in PATH variable and your file present in the same directory where you are currently at. Now, try to run this program as follows –

$ python blog.py

Your program must be present in current directory otherwise you will get this error – “python: can’t open file ‘blog.py’: [Errno 2] No such file or directory”

 

This script will produce same output.

 

This is a sample Python Program

If you want to know What is Python IDLE then brief descriptive information available here – PYTHON IDLE

a Longr Python Program

Now we’ll try to run program which has more than one-line code. When we have more than one line of code and try to execute in interpreter mode and see the result. Let’s try to print this star using
interpreter mode.

print(”   *    “)

print(”  ***   “)

print(” *****  “)

print(”  ***   “)

print(”   *    “)

If we try to enter each line one at a time into the IDLE interactive shell, the program’s output will be intermingled with the statements you type. For example –

 

>>> print(”   *    “)

   *

>>> print(”  ***   “)

  ***

>>> print(” *****  “)

 *****

>>> print(”  ***   “)

  ***

>>> print(”   *    “)

   *

>>>

 

In such scenario the best approach is to type all code into editor, save the program in file (star.py) and run the program. 

 

Most of the time we use an editor to enter and run our Python programs. The interactive interpreter is most useful for experimenting with small snippets of Python code

In this example if we run this program star.py in script mode then each print statement “draws” a horizontal slice of star.

 

$ python star.py

 

Result:

 

In Python programming, it is more important that no whitespace (spaces or tabs) come before the beginning of each statement. In Python the indentation of statements is significant and must be done properly. If we try to put a single space before a statement in the interactive shell, we get this ERROR.

 

 

An interpreter reports a similar error when we attempt to run a saved Python program if the code contains such extraneous indentation.

 

Read Mode: Python Variable, Value and Data types

Python Variable, Values and Data types

As usual in any programming language we do have Python variable, values and data types and they are essential part of our code.

Python variable

There are some specific rules must be followed when we define Variables in python. Here are those rules to define variables –

  1. Variable Name must contain at least one character.                                                         
  2. Variable Name must contain at least one character.                                                         
  3. The first character can be alphabetic letter (upper case or lower case) or the underscore.                                                                                                                                                                                                                       AxyBSNDmkerdsladCPFAEVXZkior                                                                                       
  4. The remaining characters (if any) may be alphabetic characters (upper or lower case), the underscore, or a digit.                                                                                                                                                                                   AxyBSNDmkerdsladCPFAEVXZkiorTd_02538923                                                                 
  5. No other characters (including spaces) are permitted.                                                     
  6. A reserved word cannot be used as a variable name (see below table 1.1)                  
  7. Variable names are case sensitive

Here are few examples of valid and invalid identifiers.

Valid Name    :

                           x, xY2, TekkieHead, _Myblog, _2days_BLOG, BLOG

Invalid Name :

                          5 (begins with a digit),

                          @_Blog (special characters are not allowed),

                          Tekkie%Head (special characters are not allowed),

                          Python-Program (dash is not a legal symbol in an identifier),

                          Class (reserved words are not allowed),

                          Good Read (space is not a legal symbol in an identifier)

>>> x=1000

>>> x

1000

>>> TekkieHead=”Friend of Python”

>>> TEKKIEHEAD

Traceback (most recent call last):

  File “”, line 1, in

NameError: name ‘TEKKIEHEAD’ is not defined

>>> TekkieHead

‘Friend of Python’

>>> 

>>> Tekkie%Head=”Special character in variale name”

  File “”, line 1

SyntaxError: can’t assign to operator

>>> 

Also, there are exceptions with few words which are not special, but it happens to be Python Keywords. 

You may use it as a variable name and reassign it but be careful with sequence of your code.

Python keywords : print, str, int or type

Let’s have a look what happens, if we use python keywords as a variable name.

PYTHON RESERVES 33 KEYWORDS

and del from None True
as elif global nonlocal try
assert else if not while
break except import or with
class False in pass yield
continue finally is  raise def
for lambda return    

Table 1.1

VALUES AND DATA TYPES

A value is one of the basic things on which your program works, like a letter or a number. The common types of values we use in our daily life as follows – Integer (Number), String (character or letter), float (numbers with decimal).

If you are not sure what exactly type of any value/variable, then you can use type (<value or variable name>) function.

 

The value can be assigned to variables without defining them or declaring them at first instance. Python take cares of everything when you assign the value. When we try to reassign the value from int to string, python changes the variable data types internally.

In below schematic diagram see how variable assignment and reassignment happens in Python.

 

Read More: Python IDLE 

Python IDLE, Shell and Command Prompt

Python IDLE , Shell and Command Prompt

python IDLE – Integrated Development and Learning Environment

 

Python IDLE – It is an Integrated Development Environment (IDE) for python, packaged as an optional part of the python packaging. IDLE is completely written in  python and the Tkinter GUI toolkit (wrapper functions for Tcl/Tk).

 

IDLE is intended to be simple IDE and suitable for beginners, especially in the education environment where people want to play with the Python!

 

Features
  • Multi-window text editor with syntax highlighting, auto-completion, smart indent and other.
  • Python shell with syntax highlighting.
  • Integrated debugger with stepping, persistent breakpoints, and call stack visibility.

Python 3.7 Interpreter

If you have python installed on your machine, then you will find the python executable file python.exe present at your installation directory …//python37/python.exe

If you don’t have python installed then follow this instructions to 

download and install Python

To launch the python interpreter, navigate to python.exe file and execute it. Alternative and easy way to launch interpreter would be simply search “python” or “IDLE” from your home window and launch it. You can run your python command from its interpreter window directly.

 

Python interpreter 37
Python IDLE

PYTHON SHELL & EDITOR WINDOW

IDLE has two main window types- the Shell window and the Editor window. Shell window is a default one where you can fire python commands and see the output in the same window – just below your command. 

There is limitation to use Shell window, you cannot write multiple lines of code at one go and execute it. It only allows us to write single line of code and execute it.

 

PYTHON SHELL WINDOW

Python shell is an awesome environment to work on simple commands. You can write command and just press enter to see the instant result. It also useful when you are not sure or want to check specific command or syntax.

 

>>> 10+40

50

>>> print(“Bye Byee……”)

Bye Byee……

>>> 

Python shell version 37
Python IDLE

Examples: 

Python IDLE Shell

PYTHON IDLE EDITOR

The IDLE provides us separate editor window to write your n-lines of code, save it and run it. 

 

How to open IDLE Editor: As mentioned earlier, IDLE by default opens the shell window, if you want to open editor window then follow these steps.

  1. Open IDLE shell window (which is default one)
  2. Go to “File”>> “New file”
  3. New editor window will open automatically.
  4. Write your program and save it with .py extension.

Python idle editor

 

If you have python program saved in your computer, then you can simply right click on that file and say, Edit with IDLE

Python IDLE

How to run code in IDLE?

 

Once you have your program ready, save your program in any directory and execute the program from top bar of window. 

You can see many options available on top of window like – File, Edit, Format, Run, Options, Windows, and Help.

 

You can run your program by selecting “Run” >> “Run Module” or just press “F5”. The output of your program will appear in the background “Python 3.7 Shell” window. 

If your shell window is not open at that time, then the moment you click on “run module” or press- F5 shell window will automatically open with you program output.

 

python idle run module

Configure iDLE

You can configure your code environment by setting up your favourite font size, colour adjustment and many more. All these settings you will find it in IDLE editor“Options>> Configure IDLE”

 

python idle configure

COMMAND PROMPT

How to run python code in command prompt?

There is another way of running your python code and that is through command prompt window.

If you have python installed on your machine (windows, Linux/Unix or Mac OS) you can run python interpreter through Command prompt. Go to Home window, search “cmd” and open the command prompt window.

 

Use Command Prompt as a shell

 

Type “python” to start python interpreter and enter into python shell environment where you can write commands and see the output instantly similar to shell window we saw in previous section.

The moment you enter “python” on cmd, it  also prints python interpreter details before enter into shell mode which shows installed python version details.

 

H:>python

Python 3.7.2rc1 (tags/v3.7.2rc1:75a402a217, Dec 11 2018, 23:05:39) [MSC v.1916 64 bit (AMD64)] on win32

python command prompt

Run Python code directly from command prompt

There is also possibility to run whole python program from command prompt without entering shell mode. For this, first you need to write your code using any application like notepad and save it with .py extension.

You can invoke python interpreter using py or python command.

Syntax

py  /file_path/filename.py

python /file_path/filename.py

 

Example:

python Shell cmd

What is Python?

what is python

what is python?

What is Python ? It is a high-level, structured, open-source programming language that can be used for a wide variety of programming tasks. Python was created by Guido Van Rossum in the early 1990s, its following has grown steadily & programmers are getting attracted day by day.

 

 

It is very user-friendly language, its syntax very much similar with what we write in English with some programming rules. It’s an interpreted language, it reads a high-level program and executes it, meaning that it does what the program says.

 

 

When we say it is open source it means, it is freely available on internet to download and get started with. You can download and install Python from its official website. In addition, some third-parties offer re-packaged versions of Python that add commonly used libraries and other features to ease setup for common use cases, such as math, data analysis or scientific use.

 

Features of Python

Python features a dynamic type system and automatic memory management and supports multiple programming paradigms, including object-oriented, imperative, functional programming, and procedural styles. It has a large and comprehensive standard library.

Easy to Learn: It is very simple and easy to learn language with knowing some basic programming concept, but it is not monetary. You can start with Python from scratch.

 

Easy to read: It is meant to be an easily readable language. Its formatting is visually uncluttered, and it often uses English keywords whereas other languages use punctuation.

 

High-level Language: A programming language like Python that is designed to be easy for humans to read and write.

 

Indentation: Python uses whitespace indentation, rather than curly brackets or keywords, to delimit blocks. This feature is also sometimes termed the off-side rule.

 

Interpret: To execute a program in a high-level language by translating it one line at a time.

 

Interactive: Python is very interactive & user-friendly programming language. You can interact with your program using python shell interface.

 

Multi-paradigm: Python supports functional & structural programming methods as well as Object Oriented known as a multi paradigm programming language.

 

Integrated:  It can be easily integrated with C, C++, COM, ActiveX, CORBA, and Java.

 

History of Python

Python is an open source programming language that was made to be easy-to-read and powerful. A Dutch programmer named Guido van Rossum made Python in 1991. He named it after the television show Monty Python’s Flying Circus.

 

The language’s core philosophy is summarized in the document The Zen of Python (PEP 20), which includes –

• Beautiful is better than ugly

• Explicit is better than implicit

• Simple is better than complex

• Complex is better than complicated

• Readability counts

There are major two versions of python available now (Year2018) that is, python 2.X and 3.X. Python 2.0 was released on 16 October 2000 and Python 3.0 (initially called Python 3000 or py3k) was released on 3 December 2008 after a long testing period. Python 3.X is a major revision of the language that is not completely backward-compatible with previous versions 2.X

Python Release Notes

List of python releases, you can opt any version and directly install on your computer. Installables are available on its official website python.org. Always prefer to install latest version of software which has upgraded functionality.

Python Version 3.x & 2.x

[table id=2 /]

Python is used for?

Python is used by hundreds of thousands of programmers and is used in many places. Sometimes only Python code is used for a program, but most of the time it is used to do simple jobs while another programming language is used to do more complicated tasks.

It has wide varieties of standard libraries made up of many functions that come with Python when it is installed. These libraries make it a powerful language. On the Internet there are many other libraries available that make it possible for the Python language to do more things.
Areas where python is often used:

  • Web development
  • Game programming
  • Desktop GUIs
  • Scientific programming
  • Network programming

Fun with Python

Writing python program is itself having a fun, you will get know how when you explore more python world. Here we start with our first program in python. You can write same python program in many ways as per your programming structure with same output. 

This is the first simple python program to print “Hello World!!”

print(“Hello World!”)

 

# This code does the same thing, only it is longer:

 

ready = True

if ready:

    print(“Hello World!”)

You can create variables and assign any values – number or string to them, even you reassign them multiple times at any point in your program without worrying how it internally works. 

Python is super awesome when it comes to variable assignment and memory management. 

For brief description about variables & data types in python take a look at my other post.

print(“Thanks for visiting www.tekkiehead.com”)

 

What do you think about Python?-(read again). Let me know here in comment section below!

Read More: What is Python IDLE, Shell and Command prompt

Python – Home

Python is easy to use, powerful, and versatile, making it a great choice for beginners. The readability of python code makes it great first programming language. It allows you to more concentrate on your logic instead of mysterious syntax like any other language as syntax is very simple and user friendly.

Python is a multi-paradigm, Object-oriented and structured programming language. It is an interpreted high-level programming language for general-purpose programming. Created by Guido van Rossum and first released in 1991, Python has a design philosophy that emphasizes code readability, notably using significant whitespace known as interpreter.

On the origins of Python, Van Rossum wrote in 1996:

…In December 1989, I was looking for a “hobby” programming project that would keep me occupied during the week around Christmas. My office … would be closed, but I had a home computer, and not much else on my hands. I decided to write an interpreter for the new scripting language I had been thinking about lately: a descendant of ABC that would appeal to Unix/C hackers. I chose Python as a working title for the project, being in a slightly irreverent mood (and a big fan of Monty Python’s Flying Circus).

— Guido van Rossum

New To Python?

If you haven’t programmed before or simply interested in learning another language, we have the resources to help you GET STARTED... Take a look at our comprehensive guide that introduces you to the basics of the language, and then takes you all the way through solving complex problems using python programming.

Prerequisite for Python

It would be very helpful to get started with python if you know the basic concepts of programming like variables, datatypes, functions, loops etc but it is not mandatory. If you are really interested in programming and want to start somewhere then you are on right place – Python would be great choice considering future technologies – Artificial Programming, Machine learning, Deep learning etc.

Programming Index

Many people are very curious about code. Unfortunately, choosing of programming language can be very difficult task because of scattered/lack of information available with us. The simplified general guidelines for making a good decision to choose “your programming language” may look at “The Programming index”. The index can be used to check whether your programming skills are still up to date or to make a strategic decision about what programming language should be adopted.

Measures of Programming language

There are plenty of resources available on internet which claims various different programming languages at different spots. There could be n- numbers of parameter on which languages are being indexed, each subject to a different bias over what is measured, have been proposed. Here are the few parameters – 

  •  The number of times language name is appeared on web searches.
  •  The simplicity of the language.
  • The number of programming jobs available at the moment. 
  • The number of projects in that language on SourceForge, and GitHub
  • The number of books sold that teach or describe the language

The most preferable and considerable places on internet to see the programming Index are TIOBE programming community, PYPL PopularitY of Programming Language, IEEE Spectrum ranking, Redmonk ranking etc. So let’s start with what they say…

TIOBE (The Importance of Being Earnest) Index

According to the site, TIOBE index is “not about the best programming language or the language in which most lines of code have been written”. However the site does claim that the number of web pages may reflect the number of skilled engineers, courses and jobs worldwide.

TIOBE Community Index

The ratings are calculated by counting hits of the most popular search engines. The search query that is used is +” programming”

There are 25 search engines like Google, Google Blogs, MSN, Yahoo, and Baidu etc. that are used to calculate the TIOBE index. The index is updated once a month.

TIOBE : Top 12 Programming Language

PYPL (PopularitY of Programming Language) Index

The PYPL PopularitY of Programming Language Index is created by analyzing how often language tutorials are searched on Google. The row data comes from the Google trends.
The PYPL Popularity of Programming Language index can help you decide which language to study, or which one to use in a new software project.
According to latest release note – worldwide, Python is the most popular language. Python grew the most in the last 5 years (14.3%).

PYPL Index

IEEE Spectrum Ranking

The starting from a list of over 300 programming languages the row data gathered from GitHub, Google Search and Trends, Twitter, Stack Overflow, Reddit, Hacker News, Career Builder, Dice.com, and IEEE Xplore Digital Library.

It also gives you the most personalized ranking. The interactive interface allows us to filter by search trends, job trends, or open source community trends or you can modify the weighting of each dimension, enabling an extremely personalized ranking.

IEEE Spectrum Ranking​

Looking forward….

Considering the current trend in all aspects, I would strongly recommend to start with C/C++ and jump into the future technologies – Artificial Intelligence (AI), Machine Learning (ML) and Deep learning world!! These are very broad concepts but you can begins with the Python Programming which very simple, realistic and of course most demanding language at the moment. You may check my future blog post for python programming.

Good luck in your coding journey!!

Give me your thoughts on the rankings in the comments below.

references: tiobe.com, spectrum.ieee.org, pypl.github.io


Facebook


Twitter


Linkedin