0% found this document useful (0 votes)
5 views11 pages

pyChapt-1

The document provides an introduction to Python, detailing its characteristics as a general-purpose, high-level programming language that is easy to read and maintain. It covers the history of Python's development, its various versions, and features such as being interpreted, object-oriented, and free to use. Additionally, it explains how to install Python on Windows and introduces the two modes of using the Python interpreter: interactive mode and script mode.

Uploaded by

sekije2809
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views11 pages

pyChapt-1

The document provides an introduction to Python, detailing its characteristics as a general-purpose, high-level programming language that is easy to read and maintain. It covers the history of Python's development, its various versions, and features such as being interpreted, object-oriented, and free to use. Additionally, it explains how to install Python on Windows and introduces the two modes of using the Python interpreter: interactive mode and script mode.

Uploaded by

sekije2809
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

MIT College of C.S. & I.T.

, Basmath

Unit-I

Getting Started – Introducing Python


What is python:-
“Python is a general purpose interpreted, interactive, object-oriented, and high-level
programming language.”

Python is designed to be highly readable. It uses English keywords frequently


whereas the other languages use punctuations. It has fewer syntactical constructions
than other languages.

Python is a powerful modern computer programming language. Python allows you to


use variables without declaring them, and it relies on indentation as a control
structure. Python is a good choice for mathematical calculations, since we can write
code quickly, test it easily, and its syntax is similar to the way mathematical ideas are
expressed in the mathematical literature.

Python is used for software development at companies and organizations such as


Google, Yahoo, CERN, Industrial Light and Magic, and NASA. Experienced
programmers can accomplish great things with Python, but Python’s beauty is that it
is accessible to beginning programmers and allows them to tackle interesting
problems more quickly than many other, more complex languages that have a
steeper learning curve.

History of Python:-

Python was developed by Guido van Rossum in the late eighties and early nineties
at the National Research Institute for Mathematics and Computer Science in the
Netherlands.

Python is derived from many other languages, including ABC, Modula-3, C, C++,
Algol-68, SmallTalk, and UNIX shell and other scripting languages. Guido van
Rossum publishes first python 0.9.0 in February-20, 1991.

Python is copyrighted. Like Perl, Python source code is now available under the
GNU General Public License (GPL).

There are two ways to use the interpreter:-

Interactive mode and script mode. In interactive mode, you type Python programs
and the interpreter prints the result:
>>> 1 + 1
2
The chevron, >>>, is the prompt the interpreter uses to indicate that it is ready.
If you type 1 + 1, the interpreter replies 2.

Alternatively, you can store code in a file and use the interpreter to execute the
contents of the file, which is called a script.
By convention, Python scripts have names that end with py.

Prof. Gajendra D. Dhole 1


MIT College of C.S. & I.T., Basmath

Python Versions:-

Python 0.9.0 published in 20-Feb-1991


Python 0.9.1 published in Feb-1991
Python 0.9.2 published in April-1991
Python 0.9.4 published in 24-Dec-1991
Python 0.9.5 published in 02-Jan-1992
Python 0.9.6 published in 06-April-1992
Python 0.9.8 published in 09-Jan-1992
Python 0.9.9 published in 29-July-1993

Python 1.0.0 published in Jan-1994


Python 1.2.0 published in 16-April-1995
Python 1.3.0 published in 12-Oct-1996
Python 1.4.0 published in 25-Oct-1996
Python 1.5.0 published in 31-Dec-1997
Python 1.6.0 published in 05-Sep-2000

Python 2.0.0 published in 16-Oct-2000


Python 2.1.0 published in 15-April-2001
Python 2.2.0 published in 21-Dec-2001
Python 2.3.0 published in 29-July-2003
Python 2.4.0 published in 30-Nov-2004
Python 2.5.0 published in 19-Sep-2006
Python 2.6.0 published in 01-Oct-2007
Python 2.7.0 published in 04-July-2008

Python 3.0.0 published in 03-Dec-2008


Python 3.1.0 published in 27-June-2009
Python 3.2.0 published in 20-Feb-2011
Python 3.3.0 published in 29-Sep-2012
Python 3.4.0 published in 16-Mar-2014
Python 3.5.0 published in 13-Sep-2015
Python 3.6.0 published in 23-Dec-2016
Python 3.7.0 published in 27-June-2018
.
.
.
Python 3.8.11 published in 28-June-2021
Python 3.8.12 published in 30-Aug-2021
Python 3.9.7 published in 30-Aug-2021

Prof. Gajendra D. Dhole 2


MIT College of C.S. & I.T., Basmath

Features of python:-

1. Easy-to-learn: Python has few keywords, simple structure, and a clearly


defined syntax. This allows a student to pick up the language quickly.

2. Easy-to-read: Python code is more clearly defined and visible to the eyes.

3. Easy-to-maintain: Python's source code is fairly easy-to-maintain.

4. Python is Interpreted: Python is processed at runtime by the interpreter. You


do not need to compile your program before executing it. This is similar to
PERL and PHP.

5. Python is Object-Oriented: Python class model supports advanced notions


such as polymorphism, operator overloading, and multiple inheritance

6. Python is free: python is free ware open source software. You can get the
entire system for free over the internet. There are no restrictions on copying it.

7. A broad standard library: Python's bulk of the library is very portable and
cross-platform compatible on UNIX, Windows, and Macintosh.

8. Interactive Mode: Python has support for an interactive mode, which allows
interactive testing and debugging of snippets of code.

9. Portable: Python can run on a wide variety of hardware platforms and has the
same interface on all platforms.

10. Extendable: You can add low-level modules to the Python interpreter. These
modules enable programmers to add to or customize their tools to be more
efficient.

11. Databases: Python provides interfaces to all major commercial databases.

12. GUI Programming: Python supports GUI applications that can be created
and ported to many system calls, libraries and windows systems, such as
Windows MFC, Macintosh, and the X Window system of Unix.

13. Scalable: Python provides a better structure and support for large programs
than shell scripting.

14. Python is powerful: Python provides all the simplicity and ease of use of a
scripting language along with more advanced programming tools typically
found in systems devilment language.

Prof. Gajendra D. Dhole 3


MIT College of C.S. & I.T., Basmath

Python Interpreter:-

An interpreter is like a compiler, in that it translates higher-level source code into


machine language. It works differently, however. While a compiler produces an
executable program that may run many times with no additional translation needed;
an interpreter translates source code statements into machine language as the
program runs.

An interpreter reads a high-level program and executes it, meaning that it does what
the program says. It processes the program a little at a time, alternately reading lines
and performing Computations

A compiled program does not need to be recompiled to run, but an interpreted


program must be interpreted each time it is executed. In general, compiled programs
execute more quickly than interpreted programs because the translation activity
occurs only once. Interpreted programs, on the other hand, can run as is on any
platform with an appropriate interpreter; they do not need to be recompiled to run on
a different platform.

Python, for example, is used mainly as an interpreted language, but compilers for it
are available. Interpreted languages are better suited for dynamic, explorative
development which many people feel is ideal for beginning programmers.

There are two ways to use the Python interpreter: shell mode (Interactive mode) and
script mode.
In shell mode, you type Python statements into the Python shell and the interpreter
immediately prints the result.

In this course we will be using an IDE (Integrated Development Environment) called


IDLE. When you first start IDLE it will open an interpreter window.

The python shell script starts with >>>, which is the Python prompt. The interpreter
uses the prompt to indicate that it is ready for instructions.

If we type print 1 + 1 the interpreter will reply 2 and give us another prompt.

Prof. Gajendra D. Dhole 4


MIT College of C.S. & I.T., Basmath

Installation python on windows:-

The Python download requires about 30 Mb of disk space; keep it on your machine,
in case you need to re-install Python. When installed, Python requires about an
additional 90 Mb of disk space.

Downloading

1. Click Python Download.

The following page will appear in your browser.

1. Click the Download Python 3.6.2 button.

The file named python-3.6.2.exe should start downloading into your standard
download folder. This file is about 30 Mb so it might take a while to download
fully if you are on a slow internet connection (it took me about 10 seconds
over a cable modem).

The file should appear as

2. Move this file to a more permanent location, so that you can install Python
(and reinstall it easily later, if necessary).
3. Feel free to explore this webpage further; if you want to just continue the
installation, you can terminate the tab browsing this webpage.
4. Start the Installing instructions directly below.

Prof. Gajendra D. Dhole 5


MIT College of C.S. & I.T., Basmath

Installing

1. Double-click the icon labeling the file python-3.6.2.exe.

An Open File - Security Warning pop-up window will appear.

2. Click Run.

A Python 3.6.2 (32-bit) Setup pop-up window will appear.

Ensure that the Install launcher for all users (recommended) and the Add
Python 3.6 to PATH checkboxes at the bottom are checked.

If the Python Installer finds an earlier version of Python installed on your


computer, the Install Now message will instead appear as Upgrade Now
(and the checkboxes will not appear).

Prof. Gajendra D. Dhole 6


MIT College of C.S. & I.T., Basmath

3. Highlight the Install Now (or Upgrade Now) message, and then click it.

A User Account Control pop-up window will appear, posing the question Do
you want the allow the following program to make changes to this
computer?

4. Click the Yes button.

A new Python 3.6.2 (32-bit) Setup pop-up window will appear with a Setup
Progress message and a progress bar.

During installation, it will show the various components it is installing and


move the progress bar towards completion. Soon, a new Python 3.6.2 (32-
bit) Setup pop-up window will appear with a Setup was successfully
message.

Prof. Gajendra D. Dhole 7


MIT College of C.S. & I.T., Basmath

5. Click the Close button.

Python should now be installed.

Verifying

To try to verify installation,

1. Navigate to the directory


C:\Users\Pattis\AppData\Local\Programs\Python\Python36-32 (or to
whatever directory Python was installed: see the pop-up window for installing
step 3).
2. Double-click the icon/file python.exe.

The following pop-up window will appear.

A pop-up window with the title


C:\Users\Pattis\AppData\Local\Programs\Python\Python36-32 appears,
and inside the window; on the first line is the text Python 3.6.2 ... (notice that
it should also say 32 bit). Inside the window, at the bottom left, is the prompt
>>>: type exit() to this prompt and press enter to terminate Python.

Prof. Gajendra D. Dhole 8


MIT College of C.S. & I.T., Basmath

Meeting the interpreter:-

In python there are two modes, “INTERACTIVE MODE” and “SCRIPT MODE”.

The interactive mode is a command-line shell that gives immediate feedback for
each statement, while running previously fed statements inside the active memory.
So once new lines are fed into the interpreter, the fed program is evaluated each
partly and as a full program. Interactive mode is beneficial after you simply wish to
execute basic Python commands or just wish to undertake numerous syntaxes and
easy functionalities of python.

Thus, open a command prompt in WINDOWS to call a python shell to run the
interactive mode and thereafter type “Python” and press enter.

The >>> indicates that the Python shell is ready for execution in the interactive
mode.

We can perform a number of simple tasks or run a few simple programs or test some
Python functions, using the interactive mode.

Python 3.8.1 (tags/v3.8.1:1b293b6, Dec 18 2019, 23:11:46) [MSC v.1916 64 bit


(AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> 10*10
100
>>>
>>> 10+10
20

To write long Python codes or programs having multiple files, the interactive mode is
not what I would recommend using on the first hand. Script mode would be a better
choice in such scenarios.

Using Script mode is quite easy, you have to write your code in a text file and save
the particular file with a ‘.py’ extension. .py stands for PYTHON. You can use any
available text editor.

In a standard Python shell, you can simply click “FILE” then choose “NEW” or
press “ctrl+N” to open a blank script where you can input your code. Saving the
code is quite is by pressing “Ctrl+S”. Similarly running a script in it is as easy as
pressing the key “F5”.

The syntax of the programs remains the same. “IDLE” is the popular GUI based
Python shell to write programs and perform all the functions mentioned above.

We can execute programs or scripts written in a GUI directly in a Python shell by


traversing to the exact directory (location) of the saved file and write the command
“python file_name.py” to get the output.

Prof. Gajendra D. Dhole 9


MIT College of C.S. & I.T., Basmath

Writing your first program in python:-

Python IDLE is the Python Integration Development Environment (IDE) that comes
with the Python distribution by default.

The Python IDLE is also known as an interactive interpreter. It has a number of


features such as:

 Code editing with syntax highlighting


 Smart indenting
 And auto-completion

In short, the Python IDLE helps you experiment with Python quickly in the trial-and-
error manner.

The following shows you step by step how to launch the Python IDLE and use it to
execute the Python code:

First, launch the Python IDLE program:

Prof. Gajendra D. Dhole 10


MIT College of C.S. & I.T., Basmath

A new Python Shell window will display as follows:

Now, you can enter the Python code after the cursor >>> and press Enter to execute
it.

For example, you can type the code print('Hello, World!') and press Enter, you’ll see
the message Hello, World! immediately on the screen:

Prof. Gajendra D. Dhole 11

You might also like