Getting Started With Python - Coderz*United

Getting Started With Python




History of Python

Python programming language was developed by Guido Van Rossum in February,1991.It is based or influenced by two programming languages:

  1. ABC language, a teaching language created as a replacement of BASIC.


  2. Modula-3

When he began implementing Python, Guido Van Rossum was also reading the published scripts from Monty Python’s Flying Circus, a BBC comedy series from the 1970s.

Van Rossum thought he needed a name that was short, unique, and slightly mysterious, so he decided to call the language Python.

Computational Thinking

Before starting with Python, it is important to know what all it takes to develop ‘Computational Thinking’. Computational thinking refers to the collective thought processes involved in solving problems using concepts and ideas from computer science, and expressing solutions to these problems in a form that can be effectively run or carried out on a computer. Computational Thinking is a problem solving process that involves the following characteristics: 

Decomposition

Breaking down a big or complex problem into a set of smaller sub processes in order to understand a problem or situation better.

Pattern recognition/Data Representation

• Observing or looking for similarities or patterns among and within small, decomposed problems.

• The identified patterns help solve more complex problems more efficiently.

Abstraction

• Focusing on information relevant to a context/problem and suppressing other details.

• Generalisation: Identifying common or shared characteristics between two domains or problems such that models or solutions of one could be adapted or applied to the other.

Algorithm Design

• Creation and execution of an algorithm, which is a sequence of steps that solve the design problem by working on some input data and producing a desired output.

Another step: Evaluation

  • Essential part of every type of constructive thinking including Computational Thinking.

  • Evaluation aims to check to see whether a solution reached via decomposition, pattern recognition, abstract/generalisation, algorithm design is good and effective.

Introduction to Python

Python is a high-level general-purpose programming language

that can be applied to many different classes of problems. Python is an interpreted language, not a compiled language. This means Python is executed line by line. It is an interactive, object-oriented programming language.

The Python Software Foundation is an independent non-profit organization that holds the copyright on Python versions 2.1 and newer. The PSF’s mission is to advance open source technology related to the Python programming language and to publicize the use of Python. Here’s the link to download python: DOWNLOAD (Click Download)


Features or Pluses of Python

Simple

  • Python is a simple programming language.

  • When we read a Python program, we feel like reading English sentences.

  • It means more clarity and stress on understanding the syntax of the language.

  • Hence, developing and understanding programs is easy.

Easy to learn

  • Python being a simple programming language, with just a few keywords, it is easy to learn.

High Level Language

  • Programming languages are of two types: low level and high level.

  • A low level language use machine code instructions to develop programs.

  • High level languages use English like words to develop programs. These are easy to learn and use.

Open Source

  • There is no need to pay for Python software.

  • Its source code can be read, modified and can be used in programs as desired by the programmers.

Dynamically Typed

  • In Python, we need not declare anything.

  • An assignment statement binds a name to n objects and the object can be of any type.

  • If a name is assigned to an object of one type, it may later be assigned to an object of a different type.

  • This is the meaning behind calling Python a dynamically typed language.

  • Unlike languages like C and Java, where the variables and data types should be mentioned properly before using them.

  • In these languages, assigning an object of the wrong type to a variable name triggers an error.

Platform independent

  • When a Python program is converted into an intermediary code known as byte code. This code can then be run on any system (on any operating system or hardware).

  • Using a Python Virtual Machine(PVM), anybody can run these byte code instructions on any computer system.

  • Hence, Python programs are not dependent on any specific operating system.

  • This makes Python an ideal programming language for any network or Internet.

Interpreted

  • A program code is called the source code.

  • After writing a Python program, we should compile the source code using Python compiler.

  • Python compiler translates the Python program into an intermediate code called the byte code.

  • This byte code is executed by the PVM.

  • Inside the PVM, an interpreter converts the byte code instructions into machine code so that the processor would understand and run the machine code to produce results.

Huge Library

  • Python has a big library which can be used on any operating system like Unix, Windows or Macintosh.

  • Programmers can develop programs very easily using the modules available in the Python library.

Easy to use

  • Simple syntax rules

  • Very compact and very easy to use

  • Object oriented language

Expressive language

  • Fewer lines of code, simpler syntax 

Database connectivity

  • A database represents software that stores and manipulates data.

  • Python provides interfaces to connect its programs to all major databases like Oracle, Sybase or MySql.

Variety of Usage/Applications

  • Python is used in diverse fields/applications, like:

Scripting, Web Application, Game Development, System Administration, Rapid Prototyping, GUI Programs, Database Applications.

Minuses of Python

Not the fastest language

  • Python is an interpreted language, not a compiled one.

  • Python is first semi-compiled into byte code, which is then run by a Python interpreter

  • Compiled languages are faster than interpreted languages.

  • Execution times are slow in interpreted languages.

Not strong on Type binding

  • ‘Type-mismatch’ issues are ignored by the Python interpreter. This can lead to issues in programming.

Not easily convertible

  • Most programming languages have strong syntax, whereas Python as a language which lacks much syntax, it is difficult to convert a Python program into other languages.

Mobile development

  • Python is strong in desktop and server platforms, that is it is an excellent server-side language but for mobile development, Python is not a very good language.

Memory Consumption

  • Most programming languages have strong syntax, whereas Python as a language which lacks much syntax, it is difficult to convert a Python program into other languages.

Mobile development

  • For any memory intensive tasks Python is not a good choice.

  • Python’s memory consumption is also high, due to the flexibility of the data types.

Run time errors

  • Python has errors that only show up at runtime this is because the language is dynamically typed.

Database access

  • Python’s database access layer is a bit underdeveloped and primitive.

  • It acts as a major barrier when big enterprises look for a language that ensures smooth interaction of complex legacy data.

Interactive Mode Vs Script Mode


Interactive Mode 

Script Mode

A way of using the Python interpreter by typing commands and expressions at the prompt.

A way of using the Python interpreter to read and execute statements in a script.

Can’t save and edit the code.

Can save and edit the code.

If we want to experiment with the code, we can use interactive mode.

If we are very clear about the code, we can use script mode.

We cannot save the statements for further use and we have to retype all the statements to re-run them.

We can save the statements for further use and we no need to retype all the statements to re-run them.

We can see the results immediately.

We can’t see the code immediately.




Interactive Mode

Script Mode

When Typed In

>>>print(“How old are you ?”)

How old are you ?

>>> age = 25

>>> print(age)

25

print(“How old are you ?”)

age = 25

print(age)

When Executed


How old are you ?

25

Summary

  • Python was developed by Guido Van Rossun in February 1991.

  • Python offers following advantages

    • Easy to use

    •  Expressive

    • Complete 

    • Cross-platform

    • Free and open source

  • Python also has these limitations:

    • Not the fastest language

    • Lesser libraries than C and Java

    • Not strong on Type-binding. 

  • In Python, one can work in two different ways: (i) Interactive Mode, (ii) Script Mode

  • Popular Python distributions are CPython (default), Anaconda distribution etc.

  • Popular Python IDEs are Python IDLE, Spyder IDE, Jupyter Notes, PycharmIDE etc..

  • Interactive mode does not save commands in the form of a program and also, output is sandwiched between commands.

  • Interactive mode is suitable for testing code.

  • Script mode is useful for creating programs and then running the programs later and getting complete output.

  • Python is an interpreted language.

  • Python’s interactive interpreter is also called Python Shell.