Python Programming S.Y.
-II E&TC
Unit 01:
Introduction to Python
✓ History of Python
✓ Need of Python Programming
✓ Applications Basics of Python Programming Using the REPL(Shell)
✓ Running Python Scripts
✓ Variables, Assignment, Keywords, Input-Output, Indentation.
Prof. R. R. Shriram
Dept. of E&TC Engg.
Course Structure
Teaching
Course Evaluation Scheme
Course Code Course Title Scheme Credit
Category
L T P CA MSE ESE Total
PEC-1
(Professional (E) Python
BTETPE405 3 1 - 20 20 60 100 4
Elective Programming
Course-1)
Course Outcomes
On completion of the course, student will be able to:
❑ CO405.1: Explain the concepts of interpreted language.
❑ CO405.2: Develop programs using Python Types, Operators,
Expressions, Functions and OOP concepts.
❑ CO405.3: Provide solution to real world needs by developing
software.
❑ CO405.4: Explain the concepts of testing software.
Prof. R. Shriram
Course Syllabus
4
Prof. R. Shriram
Course Syllabus
5
Course Syllabus
What is Python?
Python is a high-level programming language which is:
❑ Interpretated: Python is processed at runtime by the interpreter.
❑ Interactive: You can use a Python prompt to interact with the
interpreter directly to write your programs.
❑ Object-Oriented: Python supports Object-Oriented technique of
programming.
❑ Beginner’s Language: Python is a good language for beginner-
level programmers and supports the development of a wide
range of applications.
Prof. R. Shriram
Compiler v/s Interpreter
❑ Compiler and Interpreter are two different ways to execute a
program written in a programming or scripting language.
❑ There are two sorts of programming languages:
1. Compiled
2. Interpreted
❑ C and C++ are Compiled programming languages.
❑ Python, Perl, Matlab are Interpreted language.
Interpreter
“An Interpreter is a computer program that directly executes instructions
written in a programming or scripting language, without requiring them
previously to have been compiled into a machine language program.”
❑ The advantage of an interpreter, is that it does not need to go through
the compilation stage during which machine instructions are generated
as compilation process can be time-consuming if the program is long.
❑ The interpreter can immediately execute high-level programs.
❑ Also interpreters are used during the development of a program, when
a programmer wants to add small sections at a time and test them
quickly.
Prof. R. Shriram
Code translated into
Binary 0s and 1s.
History of Python
❑ Python was conceptualized by Guido Van Rossum in late 1980s.
❑ Rossum published the first version of Python code (0.9.0) in February
1991 at the CWI (Centrum Wiskunde & Informatica) in the Netherlands,
Amsterdam.
❑ Python is derived from ABC programming language, which is a general
programming language that had been developed at the CWI.
❑ Rossum chose the name ‘Python’, since he was a big fan of Monty
Python’s Flying Circus.
❑ Python is now maintained by a core development team at the institute,
although Rossum still holds a vital role in directing its progress.
Prof. R. Shriram
Release dates
of Python
Recent version is-
• Python 3.11.2 –
February 08, 2023
• Python 3.7 – June 27, 2018
• Python 3.8 – December 18, 2019
Why people use Python..
❑ Software Quality:
✓ Better than traditional and scripting languages
✓ Readable code, hence reusable and maintainable
✓ Support for advance reuse mechanisms
❑ Developer Productivity:
✓ Much better than statically typed languages
✓ Much smaller code
✓ Less to type, debug and maintain
✓ No lengthy compile and link steps
❑ Program Portability:
✓ Programs run unchanged on most platforms
Prof. R. Shriram
Why people use Python..
❑ Component integration:
✓ Can invoke C, C++ libraries and Java components
✓ Can communicate with frameworks such as COM, .NET
✓ Can interact over networks with interfaces like SOAP, XML-RPC ,
CORBA
✓ Popularly used for product customization and extension
❑ Powerful:
✓ Dynamic typing
✓ No variable declaration
✓ Automatic allocation and Garbage Collection
✓ Supports classes, modules and exceptions
✓ Powerful containers – Lists, Dictionaries, Tuples
Why people use Python..
❑ Ready-made stuff:
✓ For operations like joining, slicing, sorting, mapping etc.
✓ Powerful library
✓ Large collection of third party utilities
❑ Easy to use:
✓ Type and run
✓ No compile and link steps
✓ Interactive programming experience
✓ Programs are simpler, smaller and more flexible
Prof. R. Shriram
Features of Python
❑ It supports all three programming models- Procedural, Object
Oriented (OOP) and Functional.
❑ Its OOP model supports OOP features like Encapsulation,
Inheritance, Polymorphism, Operator overloading, Exception
handling.
❑ It is ideal as a scripting tool for OOP languages like C++ and Java.
❑ It is Portable and runs on every major platform currently in use.
❑ Everything in Python is an object: variables, functions, even code.
Every object has an ID, a type, and a value.
❑ Python supports automatic garbage collection.
Applications of Python
❑ System Programming
❑ GUI
❑ Internet Scripting
❑ Component Integration
❑ Database Programming
❑ Rapid Prototyping
❑ Numeric and Scientific Programming
❑ Gaming
❑ Robotics
Who uses Python today?
❑ Google – In web search system
❑ YouTube – Video sharing service
❑ Bit Torrent – Peer-to-Peer file sharing system
❑ Hardware testing – Intel, HP, Seagate, IBM, Qualcomm
❑ Movie Animation – Pixar, Industrial light and Magic
❑ Financial Market forecasting – JP Morgan, Chase, UBS
❑ Scientific programming – NASA, FermiLab
❑ Commercial Robot Vacuum Cleaners – iRobot
❑ Crptyographic & Intelligence analysis – NSA
❑ Email servers - IronPort
Prof. R. Shriram
Getting Python source code, binaries, IDE
❑ Python Official website: www.python.org
❑ Documentation website: www.python.org/doc
REPL (Shell) in Python
❑ REPL is an interactive way to talk to your computer in Python.
❑ To make this work, the computer does four things:
✓ Read the user input (your Python commands).
✓ Evaluate your code (to work out what you mean).
✓ Print any results (so you can see the computer’s response).
✓ Loop back to step 1 (to continue the conversation).
❑ The term “REPL” is an acronym for Read, Evaluate, Print and
Loop because that’s precisely what the computer does..!
Working with Python
Python Programming modes are:
[1] Interactive mode – used for exploring Python syntax, seek
help and debug short programs.
Interactive mode uses IDLE (Python
Integrated Development and Learning
Environment).
[2] Script mode – used for writing full-fledged Python programs.
Prof. R. Shriram
To use IDLE:
❑ Locate it in Windows by typing IDLE and double click it.
❑ It will open the Python shell window showing >>> Python shell
prompt.
❑ It displays the message followed by the >>> prompt.
To use Script Mode:
❑ Create a new project.
❑ Type the code.
❑ Execute the script.
Prof. R. Shriram
Keywords in Python
❑ Keywords are the reserved words which cannot be used as a
variable name, function name or any other identifier.
❑ Python has 33 keywords that are given below:
Comments in Python
❑ Comments can be used to explain Python code.
❑ Comments can be used to make the code more readable.
❑ Comments can be used to prevent execution when testing code.
❑ Comments begin with #
Comments in Python
❑ Comments begin with #
❑ Example:
or
❑ Multiline comments should be written in a pair of ‘‘‘ or ”””.
❑ Example:
Prof. R. Shriram
Indentation in Python
❑ Indentation matters in Python. (#Don’t use it casually).
❑ Following code is reported as error:
❑ Following is the correct indentation of code:
Prof. R. Shriram
Indentation in Python
❑ If statements are long they can be written as multi-lines with each
line except the last ending with a \.
Example:
❑ Statements within [ ], { }, or ( ) don’t need \.
❑ Example:
Prof. R. Shriram
Variables and Assignment in Python
❑ Variables are containers for storing data values.
❑ No need to define type of a variable in Python.
❑ Type is inferred from the context in which the variable is being
used.
❑ Simple variable assignment:
Example:
Prof. R. Shriram
Variables and Assignment in Python
❑ Multiple variable assignment:
Example:
or
or
Prof. R. Shriram
Identifiers in Python
❑ Python is a case sensitive language.
❑ Python identifier is a name used to identify a variable, function,
class, module, or other object.
❑ Rules for creating identifiers:
✓ Identifiers start with alphabet or an underscore.
✓ Followed by zero or more letters, _, and digits.
✓ They cannot start with a number.
✓ Keywords cannot be used as identifier.
Prof. R. Shriram
Identifiers in Python
❑ Examples of valid identifiers: ❑ Examples of invalid identifiers:
newvar = “hello” 2newvar = “hello”
new_var = “hello” new-var = “hello”
_new_var = “hello” new var = “hello”
newVar = “hello”
NEWVAR = “hello”
newvar2 = “hello”
Thank You!!