II-I. semester CSE (DS)
PYTHONPROGRAMMING
COMPLETE NOTES
Prepared by:
Dr.M.Purushotham
Professor
Dept. of CSE (DS)
Sreyas Institute of Engineering and Technology
Nagole, Hyderabad.
2022-23
SREYAS INSTITUTE OF ENGINEERING AND TECHNOLOGY
, PYTHON PROGRAMMING
SYLLABUS
UNIT-I
Python Basics, Objects- Python Objects, Standard Types, Other Built-in Types,
InternalTypes,StandardTypeOperators,StandardTypeBuilt-
inFunctions,CategorizingtheStandardTypes,UnsupportedTypes.
Numbers - Introduction to Numbers, Integers, Floating Point Real Numbers,
ComplexNumbers,Operators,Built-inFunctions,RelatedModules
Sequences-Strings,Lists, andTuples,MappingandSetTypes
UNIT- II
FILES: File Objects, File Built-in Function [ open() ], File Built-in Methods, File Built-
inAttributes,StandardFiles,Command-
lineArguments,FileSystem,FileExecution,PersistentStorage Modules,RelatedModules.
Exceptions:ExceptionsinPython,DetectingandHandlingExceptions,ContextManagement,*
ExceptionsasStrings,RaisingExceptions,Assertions,StandardExceptions,*Creating
Exceptions,Why Exceptions (Now)?,Why Exceptions atAll?,Exceptionsandthe sys
Module,RelatedModules.
Modules:ModulesandFiles,Namespaces,ImportingModules,ImportingModuleAttributes,M
odule Built-inFunctions,Packages,OtherFeaturesofModules
UNIT-III
Regular Expressions: Introduction, Special Symbols and Characters, Res and
PythonMultithreadedProgramming:Introduction,ThreadsandProcesses,Python,Threads,and
theGlobalInterpreterLock,Thread Module,Threading Module,Related Modules
UNIT- IV
GUI Programming: Introduction, Tkinter and Python Programming, Brief Tour of
OtherGUIs,RelatedModules andOtherGUIs
WEBProgramming:Introduction,WedSurfingwithPython,CreatingSimpleWebClients,
Advanced Web Clients, CGI-Helping Servers Process Client Data, Building
CGIApplicationAdvancedCGI,Web(HTTP)Servers
UNIT–V
Database Programming: Introduction, Python Database
ApplicationProgrammer’sInterface(DB-
API),ObjectRelationalManagers(ORMs),RelatedModules
TEXTBOOK:
CorePythonProgramming,WesleyJ. Chun, SecondEdition, Pearson
SREYAS INSTITUTE OF ENGINEERING AND TECHNOLOGY
, 1
UNITI–INTRODUCTION TOPYTHON
1.1 PythonBasics
Python is a high-level, interpreted, interactive and object-oriented scripting 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.
1. Pythonis Interpreted− Python is processed at runtime by the interpreter. You donot
need to compile your program before executing it. This is similar to PERL and PHP.
2. Python is Interactive − You can actually sit at a Python prompt and interact with the
interpreter directly to write your programs.
3. Python is Object-Oriented − Python supports Object-Oriented style or technique
ofprogrammingthatencapsulatescodewithinobjects.
4. Python is a Beginner's Language − Python is a great language for the beginner-
levelprogrammers and supports the development of a wide range of applications
fromsimple textprocessingtoWWW browsers togames.
History of Python:
Python was developed by Guidovan Rossumin the late eighties and early nineties at the
National Research Institute for Mathematics and Computer Science in the Netherlands.
Pythonisderivedfrommanyotherlanguages,includingABC,Modula-3,C,C++,Algol-
68,SmallTalk,andUnixshellandotherscriptinglanguages.
➢ Pythonis copyrighted. LikePerl,Pythonsourcecodeis
nowavailableundertheGNUGeneralPublicLicense(GPL).
➢ Pythonisnowmaintainedbyacoredevelopmentteamattheinstitute,althoughGuidovanRos
sumstillholds a vitalroleindirectingitsprogress.
➢ Python1.0wasreleasedinNovember1994.In2000,Python2.0wasreleased.Python
2.7.11isthelatesteditionofPython2.
➢ Meanwhile, Python 3.0 was released in 2008. Python 3 is not backward compatiblewith
Python 2. The emphasis in Python 3 hadbeen on the removal of duplicateprogramming
constructs and modules so that "There should be one -- and preferablyonlyone--
obviouswaytodoit."Python3.5.1isthelatestversionofPython3.
PythonFeatures:
1. Easy-to-
learn−Pythonhasfewkeywords,simplestructure,andaclearlydefinedsyntax.Thisallowsa
studenttopickupthe language quickly.
2. Easy-to-read−Pythoncodeis moreclearlydefinedandvisibletotheeyes.
3. Easy-to-maintain−Python'ssourcecodeis fairlyeasy-to-maintain.
4. Abroadstandardlibrary−Python'sbulkofthelibraryisveryportableandcross-
platformcompatibleonUNIX,Windows,andMacintosh.
5. InteractiveMode−Pythonhassupportforaninteractivemodewhichallowsinteractive
testinganddebuggingofsnippets ofcode.
M. Naresh Choudary | SREYAS INSTITUTE OF ENGINEERING AND TECHNOLOGY
, 2
6. Portable−Pythoncanrunonawidevariety ofhardwareplatformsandhasthesameinterface
onallplatforms.
7. Extendable−Youcanaddlow-
levelmodulestothePythoninterpreter.Thesemodulesenableprogrammersto
addtoorcustomizetheirtoolsto bemoreefficient.
8. Databases−Pythonprovides interfacestoallmajorcommercialdatabases.
9. GUI Programming − Python supports GUI applications thatcan be created andported
to many system calls, libraries and windows systems, such as Windows
MFC,Macintosh,andtheX WindowsystemofUnix.
10. Scalable − Python provides a better structure and supportfor large programs
thanshellscripting.
1.2 PythonObjects
Python uses the object model abstraction for data storage. Any construct that
containsanytypeofvalueisanobject.AlthoughPythonisclassifiedasan"object-
orientedprogramming (OOP) language," OOP is not required to create perfectly working
Pythonapplications. You can certainly write a useful Python script without the use of classes
andinstances. However, Python's object syntax and architecture encourage or "provoke" this
typeofbehavior.Letusnowtakea closerlookatwhata Pythonobjectis.
All Python objects have the following three characteristics: an identity, a type, and a
value.IDENTITY--
Uniqueidentifierthatdifferentiatesanobjectfromallothers.Anyobject'sidentifiercanbeobtainedus
ingtheid()built-
infunction(BIF).Thisvalueisascloseasyouwillgettoa"memoryaddress"inPython(probablymucht
othereliefofsomeofyou).Evenbetteristhatyou rarely,ifever,accessthisvalue,much
lesscarewhatitisatall.
TYPE--An object's typeindicates whatkind of values an objectcan hold,whatoperationscan be
applied to such objects, and what behavioral rules these objects are subject to. You canuse the
type() BIF to reveal the type of a Python object. Since types are also objects in Python(did we
mention that Python was object-oriented?), type() actually returns an object to
youratherthanasimpleliteral.
VALUE--Dataitemthatisrepresentedbyanobject.
All three are assigned on object creation and are read-only with one exception, thevalue.
(For new-style types and classes, it may possible to change the type of an object, butthis is not
recommended for the beginner.) If an object supports updates, its value can
bechanged;otherwise,itis alsoread-only.
Whether an object's value can be changed is known as an object's mutability.
Thesecharacteristicsexistaslongastheobjectdoesandarereclaimedwhenanobjectisdeallocated.
Python supports a set of basic (built-in)data types,as well as some auxiliary
typesthatmay comeintoplay if your application requires them. Mostapplications generally
usethestandardtypesandcreateandinstantiate classesforallspecializeddatastorage.
M. Naresh Choudary | SREYAS INSTITUTE OF ENGINEERING AND TECHNOLOGY