0% found this document useful (0 votes)
2 views

Module 1

Python is a high-level, interpreted programming language known for its readability and versatility, supporting multiple programming paradigms including object-oriented and functional programming. It is widely used in various fields such as web development, database programming, and GUI applications, and is favored for its rapid development capabilities and ease of integration with other languages and systems. Python has several implementations, including CPython, Jython, and IronPython, making it accessible across different platforms.

Uploaded by

ahad siddiqui
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Module 1

Python is a high-level, interpreted programming language known for its readability and versatility, supporting multiple programming paradigms including object-oriented and functional programming. It is widely used in various fields such as web development, database programming, and GUI applications, and is favored for its rapid development capabilities and ease of integration with other languages and systems. Python has several implementations, including CPython, Jython, and IronPython, making it accessible across different platforms.

Uploaded by

ahad siddiqui
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 34

Module 1- An Overview of Python

1
© Nex-G Exuberant Solutions Pvt. Ltd.
Introduction

• Python is a general-purpose interpreted, interactive, object-oriented and high-level


programming language.

• Its design emphasizes code readability, and its syntax allows programmers to
express concepts in fewer lines of code than would be possible in languages such as
C++ or Java].

• The language provides constructs intended to enable clear programs on both a small
and large scale

• Python supports multiple programming, including object-oriented, imperative and


functional programming or procedural styles.

• One of the friendly things about Python is that it allows you to type directly into the
interactive interpreter—the program that will be running your Python programs. You
can access the Python interpreter using a simple graphical interface called the
Interactive Development Environment (IDLE).
2
© Nex-G Exuberant Solutions Pvt. Ltd.
What is python

• Python is an interpreted, object-oriented, high-level programming language with


dynamic semantics. Its high-level built-in data structures, combined with dynamic typing
and dynamic binding, make it very attractive for Rapid Application Development, as well
as for use as a scripting or glue language to connect existing components together.

• Python's simple, easy to learn syntax emphasizes readability and therefore reduces the
cost of program maintenance.

• Python supports modules and packages, which encourages program modularity and
code reuse.

• The Python interpreter and the extensive standard library are available in source or
binary form without charge for all major platforms and can be freely distributed.
3
© Nex-G Exuberant Solutions Pvt. Ltd.
Is Python a “Scripting Language”?

• Python is a general-purpose programming language that is often applied in scripting roles.


It is commonly defined as an object-oriented scripting language—a definition that blends
support for OOP with an overall orientation toward scripting roles. In fact people often use
the word “script” instead of “program” to describe a Python code file.

• Generally “script” is used to describe a simple top-level file and “program” to refer to a
more sophisticated multiline application.

• Because the term “scripting language” has so many different meanings to different
observers, some would prefer that it not be applied to Python at all.

4
© Nex-G Exuberant Solutions Pvt. Ltd.
Properties of Python

Shell tools

• Python is a tool for coding operating-system-oriented scripts. Such programs are often
launched from console command lines and perform tasks such as processing text files
and launching other programs.

• Python programs can and do serve such roles, but this is just one of dozens of common
Python application domains. It is not just a better shell-script language.

5
© Nex-G Exuberant Solutions Pvt. Ltd.
Properties of Python

Control language

• To others, scripting refers to a “glue” layer used to control and direct (i.e., script) other
application components. Python programs are indeed often deployed in the context of
larger applications. For instance, to test hardware devices, Python programs may call out
to components that give low-level access to a device. Similarly, programs may run bits of
Python code at strategic points to support end-user product customization without the
need to ship and recompile the entire system’s source code.

• Python’s simplicity makes it a naturally flexible control tool. Technically, though, this is
also just a common Python role; many (perhaps most) Python programmers code
standalone scripts without ever using or knowing about any integrated components.

• It is not just a control language.

6
© Nex-G Exuberant Solutions Pvt. Ltd.
Properties of Python

Ease of use

• Probably the best way to think of the term “scripting language” is that it refers to a simple
language used for quickly coding tasks. This is especially true when the term is applied to
Python, which allows much faster program development than compiled languages like C+
+. Its rapid development cycle fosters an exploratory, incremental mode of programming
that has to be experienced to be appreciated.

7
© Nex-G Exuberant Solutions Pvt. Ltd.
Why Python?

• Software quality : Python makes it easy to write software that can be understood, reused, and
modified. By design, Python implements a deliberately simple and readable syntax and a highly
coherent programming model

• Developer productivity: Python is optimized for speed of development. It's easy to write
programs fast in Python, because the interpreter handles details you must code explicitly in more
complex, lower-level languages. Things such as type declarations, storage layout, memory
management, common task implementations, and build procedures are nowhere to be found in
Python scripts

• Program portability: Most Python programs run without modification on nearly every computer
system in use today on Windows, Linux.

• Component integration : Programs written in Python can be easily mixed with and can script
other components of a system.

8
© Nex-G Exuberant Solutions Pvt. Ltd.
Python Use in various Fields

Python in Component integration :

• Python code can invoke C/C++ libraries and can be called from C/C++.
For example, integrating a C library into Python enables Python to test and launch the
library's component, and embedding Python in a product enables onsite customizations to
be coded without having to recompile the entire product.

• It can integrate with Java and .Net components, and it can communicate over frameworks
such as COM. It also can interface with devices over serial ports, and can interact over
networks with interfaces like SOAP, XML-RPC, and COBRA.

9
© Nex-G Exuberant Solutions Pvt. Ltd.
Python Use in various Fields

Another alternative ways to script components are:

• Cython system allows coders to mix Python and C-code.

• SWIG and SIP code generators can automate much of the work needed to link compiled
components into Python.

• Python's COM support.

• Iron Python .NET frameworks based implementation.

• Jython: Java-based implementation.

• COBRA toolkits for Python.

10
© Nex-G Exuberant Solutions Pvt. Ltd.
Python Use in various Fields

Python in Database Programming

• For general database, Python gives us interfaces to all RDBS - Sybase, Oracle, MySQL,
PostgreSQL, and SQLite.

• Python's standard pickle module provides a simple object persistence system.

Python in GUI

• Python's simplicity and rapid turnaround make it a good match for graphical user interface
programming. Python comes with a object-oriented interface to the Tk GUI API
called tkinter which allows Python to implement portable GUIs with native look and feel.

• Python/tkinter GUIs run unchanged for different platforms.

11
© Nex-G Exuberant Solutions Pvt. Ltd.
Python Use in various Fields

Python in Internet Scripting

Python using Socket module:

– Communicate over sockets.

– Extract form information sent to server-side CGI scripts.

– Transfer files by FTP.

– Parse, generate, and analyse XML files.

– Send, receive, compose, and parse email.

– Fetch web pages by URLs.

– Parse the HTML and XML of fetched web pages.

– Communicate over XML-RPC, SOAP, and Telnet.

12
© Nex-G Exuberant Solutions Pvt. Ltd.
Python Use in various Fields

• There are framework web development packages for Python:

– Django

– TurboGears

– web2.py

– Pylons

– Zope

– WebWare

13
© Nex-G Exuberant Solutions Pvt. Ltd.
Python Implementations

Python currently has three production-quality implementations, known as


CPython, Jython, and IronPython, and several other experimental
implementations, such as PyPy.

1. CPython

• Classic Python (often just called Python) is the fastest, most up-to-date, most solid and
complete implementation of Python. Therefore, it can be considered the "reference
implementation" of the language.

• CPython is a compiler, interpreter, and set of built-in and optional extension modules, all
coded in standard C.

• CPython can be used on any platform where the C compiler complies with the ISO/IEC
9899:1990 standard (i.e., all modern, popular platforms

14
© Nex-G Exuberant Solutions Pvt. Ltd.
Python Implementations

2. Jython

• Jython is a Python implementation for any Java Virtual Machine (JVM) compliant with
Java 1.2 or better.

• With Jython, you can use all Java libraries and frameworks. For optimal use of Jython,
you need some familiarity with fundamental Java classes.

• You do not have to code in Java, but documentation and examples for existing Java
classes are couched in Java terms, so you need a nodding acquaintance with Java to
read and understand them.

• You also need to use Java supporting tools for tasks such as manipulating .jar files and
signing applets

15
© Nex-G Exuberant Solutions Pvt. Ltd.
Python Implementations

3. IronPython

• IronPython is a Python implementation for the Microsoft-designed Common Language


Runtime (CLR), most commonly known as .NET.

• With IronPython, you can use all CLR libraries and frameworks. In addition to Microsoft's
own implementation, a cross-platform implementation of the CLR (known as Mono) works
with other, non-Microsoft operating systems, as well as with Windows. For optimal use of
IronPython, you need some familiarity with fundamental CLR libraries.

• You do not have to code in C#, but documentation and examples for existing CLR libraries
are often couched in C# terms, so you need a nodding acquaintance with C# to read and
understand them. You also need to use CLR supporting tools for tasks such as making
CLR assemblies

16
© Nex-G Exuberant Solutions Pvt. Ltd.
Python Features

 Easy-to-learn: Python has relatively few keywords, simple structure, and a clearly defined
syntax. This allows the student to pick up the language in a relatively short period of time.

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

 Interactive Mode: Support for an interactive mode in which you can enter results from a
terminal right to the language, allowing interactive testing and debugging of snippets of code.

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

17
© Nex-G Exuberant Solutions Pvt. Ltd.
Python Features

 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.

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

 Support for functional and structured programming methods as well as OOP.

 It can be used as a scripting language or can be compiled to byte-code for building


large applications.

 Very high-level dynamic data types and supports dynamic type checking..

 It can be easily integrated with C, C++, COM, ActiveX, CORBA and Java

18
© Nex-G Exuberant Solutions Pvt. Ltd.
Who Uses Python Today

• Python is automatically included with Linux distributions, Macintosh computers,


and some products and hardware, further clouding the user-base picture.

• Python is also being applied in real revenue-generating products by real companies. For
instance:

• Google makes extensive use of Python in its web search systems, and employs
Python’s creator.

• The YouTube video sharing service is largely written in Python.

• The popular BitTorrent peer-to-peer file sharing system is a Python program.

• Google’s popular App Engine web development framework uses Python as its
application language.

19
© Nex-G Exuberant Solutions Pvt. Ltd.
Who Uses Python Today

• EVE Online, a Massively Multiplayer Online Role Playing Game (MMORPG), makes
extensive use of Python.

• Maya, a powerful integrated 3D modelling and animation system, provides a Python


scripting API.

• Intel, Cisco, Hewlett-Packard, Seagate, Qualcomm, and IBM use Python for hardware
testing.

• And so on. Probably the only common thread amongst the companies using Python today
is that Python is used all over the map, in terms of application domains. Its general-
purpose nature makes it applicable to almost all fields, not just one. In fact, it’s safe to
say that virtually every substantial organization writing software is using Python, whether
for short-term tactical tasks, such as testing and administration, or for long term strategic
product development

20
© Nex-G Exuberant Solutions Pvt. Ltd.
Comparing Python to Other Languages

Java

• Python programs are generally expected to run slower than Java programs, but they
also take much less time to develop. Python programs are typically 3-5 times shorter than
equivalent Java programs.

• Python has built-in high-level data types and dynamic typing. A Python programmer
wastes no time declaring the types of arguments or variables, and Python's powerful
polymorphic list and dictionary types, for which rich syntactic support is built straight into
the language, find a use in almost every Python program.

• Because of the run-time typing, Python's run time must work harder than Java's.

• For these reasons, Python is much better suited as a "glue" language, while Java is
better characterized as a low-level implementation language

21
© Nex-G Exuberant Solutions Pvt. Ltd.
Comparing Python to Other Languages

Javascript

• Python's "object-based" subset is roughly equivalent to JavaScript. Like JavaScript (and


unlike Java), Python supports a programming style that uses simple functions and
variables without engaging in class definitions

Perl

• Python and Perl come from a similar background (Unix scripting, which both have long
outgrown), and sport many similar features

• Perl emphasizes support for common application-oriented tasks, e.g. by having built-in
regular expressions, file scanning and report generating features. Python emphasizes
support for common programming methodologies such as data structure design and
object-oriented programming, and encourages programmers to write readable code by
providing an elegant but not overly cryptic notation.

22
© Nex-G Exuberant Solutions Pvt. Ltd.
Comparing Python to Other Languages

Tcl

• Like Python, Tcl is usable as an application extension language, as well as a stand-alone


programming language.

• However, Tcl, which traditionally stores all data as strings, is weak on data structures, and
executes typical code much slower than Python.

• Tcl also lacks features needed for writing large programs, such as modular namespaces

23
© Nex-G Exuberant Solutions Pvt. Ltd.
Comparing Python to Other Languages

C++

• Python and C++ are extremely different languages.

• No compile step in Python .

• No memory management. You don't have to explicitly allocate memory for new
variables, and you don't have to explicitly free memory you're done with. The interpreter
will allocate memory for you and free it when it's safe to do so.

• High-level native data types. Strings, tuples, lists, sets, dictionaries, file objects and
more are built-in. As an example, {"x": "y"} defines a dictionary (hash table) with string "x"
as a key and string "y" as its value.

• Especially clean, straightforward syntax. This is a major goal of the Python language.
Programmers familiar with C and C++ will find the syntax familiar yet much simpler
without all the braces and semicolons

• Slower than C++ in run-time, faster in development time.


24
© Nex-G Exuberant Solutions Pvt. Ltd.
Python Timeline

•Python was conceived in the late 1980s.

•Guido van Rossum, Benevolent Dictator For Life


→ Rossum is Dutch, born in Netherlands, Christmas break bored, big fan of Monty
python’s Flying Circus
→ Descendant of ABC, he wrote glob() function in UNIX
→ M.D. @ U of Amsterdam, worked for CWI, NIST, CNRI,
Google Also, helped develop the ABC programming language

•In 1991 python 0.9.0 was published and reached the masses through alt.sources

•In January of 1994 python 1.0 was released


→ Functional programming tools like lambda, map, filter
→ comp.lang.python formed, greatly increasing python’s userbase

25
© Nex-G Exuberant Solutions Pvt. Ltd.
Python Timeline

• In 1995, python 1.2 was released.

• By version 1.4 python had several new features


→ Keyword arguments (similar to those of common lisp)
→Built-in support for complex numbers
→Basic form of data-hiding through name mangling (easily

bypassed however)

• Computer Programming for Everybody (CP4E) initiative


→ Make programming accessible to more people, with basic “literacy” similar
to those required for English and math skills for some jobs.
→ Project was funded by DARPA
→ CP4E was inactive as of 2007, not so much a concern to get

26
employees programming© “literate”
Nex-G Exuberant Solutions Pvt. Ltd.
Python Timeline

• In 2000, Python 2.0 was released.


→ Introduced list comprehensions similar to Haskells
→ Introduced garbage collection
• In 2001, Python 2.2 was released.
→ Included unification of types and classes into one hierarchy,
making pythons object model purely Object-oriented
→ Generators were added(function-like iterator behavior)
• Python 3.0 released in 2008
• Python 3.6 released in 2016
• Python 3.7 released in 2018
• Python 3.8 released in 2019
• Python 2.7 deprecated in 2020 (No longer supported or updated)
• Python 3.9 released in 2020 (Under “bugfix” status, not stable)
• Python 3.10 released in 2021 (Under “bugfix” status, not stable)
27
© Nex-G Exuberant Solutions Pvt. Ltd.
Timeline Summary

Python 1.0 - January 1994 Python 3.5 - September 13, 2015


Python 1.5 - December 31, 1997 Python 3.6 - December 16, 2016
Python 1.6 - September 5, 2000 Python 3.7 - June 27, 2018
Python 2.0 - October 16, 2000 Python 3.8 - October 14, 2019
Python 2.1 - April 17, 2001 Python 3.9 - October 5, 2020
Python 2.2 - December 21, 2001 Python 3.10 - October 4, 2021
Python 2.3 - July 29, 2003
Python 2.4 - November 30, 2004
Python 2.5 - September 19, 2006
Python 2.6 - October 1, 2008
Python 2.7 - July 3, 2010
Python 3.0 - December 3, 2008
Python 3.1 - June 27, 2009
Python 3.2 - February 20, 2011
Python 3.3 - September 29, 2012
Python 3.4 - March 16, 2014

28
© Nex-G Exuberant Solutions Pvt. Ltd.
Which version of Python

Python 2.7
• Current version on Eniac, so we’ll NOT use it, because it is deprecated.
• Last stable release before version 3
• Implements some of the new features in version 3, but fully backwards compatible

Python 3
• Released in 2008
• Many changes (including incompatible changes)
• Much cleaner language in many ways
• Strings use Unicode, not ASCII
• A lot of important third-party libraries are compatible with Python 3

© Nex-G Exuberant Solutions Pvt. Ltd.


Disadvantages of Python

Disadvantages:
• Python isn't the best for memory intensive tasks.
• Python is interpreted language & is slow compared to C/C++ or java.
• Python not a great choice for a high-graphic 3d game that takes up a lot of CPU.
• Python is evolving continuously, with constant evolution there is little substantial
documentation available for the language.

30
© Nex-G Exuberant Solutions Pvt. Ltd.
Commenting in Python

# Comments:

• Hash-mark comments are the most basic way to document your code.

• Python simply ignores all the text following a #

• Such comments are accessible only in your source files, though; to code comments that
are more widely available, you’ll need to use docstrings.

• In fact, current best practice generally dictates that docstrings are best for larger
functional documentation (e.g., “my function/method does this”), and # comments are best
limited to smaller code documentation.

31
© Nex-G Exuberant Solutions Pvt. Ltd.
Some important functions/attributes

The dir Function

• The built-in dir function is an easy way to grab a list of all the attributes available inside an
object (i.e., its methods and simpler data items). It can be called on any object that has
attributes. For example, to find out what’s available in the standard library’s sys module,
import it and pass it to dir >>> import sys
>>> import sys
>>> dir(sys)
['__breakpointhook__', '__displayhook__', '__doc__', '__excepthook__',
'__interactivehook__', '__loader__', '__name__', '__package__', '__spec__', '__stderr__',
'__stdin__', '__stdout__', '__unraisablehook__', '_base_executable', '_clear_type_cache',
'_current_frames', '_debugmallocstats', '_enablelegacywindowsfsencoding', '_framework',
'_getframe', '_git', '_home', '_xoptions', 'addaudithook', 'api_version', 'argv', 'audit',
'base_exec_prefix', 'base_prefix', 'breakpointhook', 'builtin_module_names', 'byteorder',
'call_tracing', 'callstats', 'copyright’,…]

32
© Nex-G Exuberant Solutions Pvt. Ltd.
Some important functions/attributes

Docstrings:
• Available by using __doc__ attribute

• Besides # comments, Python supports documentation that is automatically attached to


objects and retained at runtime for inspection.

• Syntactically, such comments are coded as strings at the tops of module files and function
and class statements, before any other executable code (# comments are OK before
them). Python automatically stuffs the strings, known as docstrings, into the __doc__
attributes of the corresponding objects

33
© Nex-G Exuberant Solutions Pvt. Ltd.
Getting help with pydoc

• The pydoc module automatically generates documentation from Python modules. The
documentation can be presented as pages of text on the console, served to a Web
browser, or saved to HTML files.

• The built-in function help() invokes the online help system in the interactive interpreter,
which uses pydoc to generate its documentation as text on the console. The same text
documentation can also be viewed from outside the Python interpreter by running pydoc
as a script at the operating system’s command prompt.

• For example, running “pydoc sys” in shell terminal / command prompt

• at a shell prompt will display documentation on the sys module, in a style similar to the
manual pages shown by the Unix man command. The argument to pydoc can be the
name of a function, module, or package, or a dotted reference to a class, method, or
function within a module or module in a package

34
© Nex-G Exuberant Solutions Pvt. Ltd.

You might also like