Python Unit 1
Python Unit 1
By AYUSHI
Agenda:
❑ What is Python?
❑ Why Python?
❑ Differences between Programming and Scripting Language
❑ History of Python
❑ Scope of Python
❑ What can I do with python ?
❑ Who uses Python today?
❑ Why do people use python?
❑ Installing Python IDE
❑ A Sample Code
❑ Python Code Execution
❑ Running Python
❑ Python Basic (Variables, Strings, Data types, etc.)
❑ Operators and Expressions
WHAT IS PYTHON?
▪ Python is a general-purpose interpreted, interactive, object-oriented, and
▪ Python can be used for simple tasks such as plotting or for more complex tasks
▪ Python : Run->test->Edit->Run
▪ Others: Run->Test->edit->Recompile->Link->Run
▪ Python is an interpreted, high-level, general-purpose programming
▪ Write a code
▪ The programmer writes the code, ▪ The programmer writes the code and then
compiles it, and executes it. runs it.
▪ The code is compiled into an executable ▪ The code is directly interpreted by the Python
file. interpreter.
▪ The code is run on a computer. ▪ The code is run on a Python interpreter.
▪ The programmer must declare variables ▪ The programmer does not need to declare
before using them. variables before using them.
▪ The programmer needs to specify the data ▪ The programmer does not need to specify the
type of the variables. data type of the variables.
▪ The programmer needs to free the ▪ The interpreter automatically releases the
memory allocated for the variables. memory allocated for the variables.
▪ The programmer needs to handle memory ▪ The interpreter handles memory
management. management.
▪ The code is executed on a specific ▪ The code is executed on any platform that has
platform. a Python interpreter.
WHY PYTHON?
▪ It’s simple, and less complicated code which can be developed much lesser time than other languages and
easily maintained.
▪ Because a programmer's time to develop code is more expensive than a computer's time to run that code.
Python is a good language for programmers to stay very productive.
▪ It is used to develop an application or software from scratch. ▪ It is used to combine existing components and automate a specific task.
▪
▪ It runs or executes independently and does not depend on the parent ▪ It runs or executes inside another program.
(exterior) program ▪
▪ It uses an interpreter to convert source code into machine code.
▪ It uses a compiler to convert source code into machine code.
▪ As it uses an interpreter, hence the program is converted into machine
▪ As it uses a compiler, hence the complete program is converted into code line by line.
machine code in one shot.
▪ It is comparatively difficult to write code in a programming language,
▪ It is comparatively difficult to write code in a programming language, and and it requires numerous lines of code for each task.
it requires numerous lines of code for each task.
▪ The development time in a scripting language as a smaller number of
▪ The development time in programming languages is high as more lines lines are required.
are required.
▪ There is less maintenance cost.
▪ There is the high maintenance cost.
▪ All scripting languages are programming languages.
▪ All programming languages are not scripting languages.
▪ It does not create .exe file.
▪ It generates a .exe file.
▪ Scripting languages provide great support to user interface design, data
▪ Usually, programming languages do not support or provide very little types, and graphic design.
support for user interface designing, data types, and graphic designing.
▪ Some popular examples are Perl, Python, JavaScript, etc.
▪ Some popular examples are C, C++, Java, Scala, COBOL, etc.
HISTORY OF PYTHON
▪ Python laid its foundation in the late 1980s.
▪ The implementation of Python was started in December 1989 by Guido Van Rossum at CWI in
Netherland.
▪ In February 1991, Guido Van Rossum published the code (labeled version 0.9.0) to
alt.sources.
▪ In 1994, Python 1.0 was released with new features like lambda, map, filter, and reduce.
▪ Python 2.0 added new features such as list comprehensions, garbage collection systems.
▪ On December 3, 2008, Python 3.0 (also called "Py3K") was released. It was designed to rectify
the fundamental flaw of the language.
▪ ABC programming language is said to be the predecessor of Python language, which was
capable of Exception Handling and interfacing with the Amoeba Operating System.
▪ The following programming languages influence Python:
▪ ABC language.
▪ Modula-3
▪ Open sourced from the beginning.
HOW IT IS NAMED AS PYTHON?
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.
PYTHON’S BENEVOLENT DICTATOR FOR LIFE
“ Python is experiment in
how much freedom
programmers need. Too
much freedom and nobody
can read another’s code; too
little and expensiveness is
endangered.”
-Guido Van
Rossum
WHY WAS PYTHON CREATED?
“My original motivation for creating Python was the perceived need for a
higher level language in the Amoeba [operating systems] project.
So, there was need for a language that would bridge the gap
between C and the shell.”
▪ System Administration
▪ Unix
▪ Web logic
▪ Web Sphere
▪ Testing Scripts
WHAT CAN WE DO WITH PYTHON?
System Programming
Internet Scripting
Component Integration
Database Programming
▪ For instance:
▪ Google makes extensive use of Python in its web search system and employs
Python’s creator.
▪ Intel, Cisco, Hewlett-Packard, Seagate, Qualcomm, and IBM use Python for
hardware testing.
▪ ESRI uses Python as an end-user customization tool for its popular GIS mapping
products.
▪ The YouTube video sharing service is largely written in Python.
WHY DO PEOPLE USE PYTHON?
The following primary factors cited by Python users seem to be ▪ It’s portable
these: ▪ Python runs virtually every major platform
▪ IDE is basically a software pack that consist of equipment’s which are used for developing and
testing the software.
▪ A developer throughout SDLC uses many tools like editors, libraries, compiling and testing
platforms.
▪ IDE helps to automate the task of a developer by reducing manual efforts and combines all
the equipment’s in a common framework.
▪ If IDE is not present, then the developer has to manually do the selections, integrations and
deployment process. IDE was basically developed to simplify the SDLC process, by reducing
coding and avoiding typing errors.
PYTHON IDES
▪ Pycharm
▪ Jupyter Notebook
▪ Enthought Canopy
▪ Spyder
▪ Pydev
▪ Wing
IDLE
IDLE SCRIPT WRITER(FROM FILE SELECT NEW)
SAVE WITH .PY EXTENSION
IDLE IS A POPULAR INTEGRATED DEVELOPMENT LEARNING ENVIRONMENT WRITTEN IN
PYTHON AND IT HAS BEEN INTEGRATED WITH THE DEFAULT LANGUAGE.
▪ IDLE is a very simple and basic IDE which is mainly used by the beginner level developers
who want to practice on python development
▪ IDLE is developed purely in Python with the usage of Tkinter GUI toolkit
▪ It has a good feature of multi-window text editor which has many features like call tips, smart
indentation, undo and python colorizing.
OTHER EDITOR INTERFACES
PYCHARM IS ONE OF THE WIDELY USED PYTHON IDE WHICH WAS CREATED BY JET
BRAINS. IT IS ONE OF THE BEST IDE FOR PYTHON.
PYCHARM
Pros.
1. It comes with an intelligent code editor, smart code
navigation
2. PyCharm is integrated with features like debugging, testing,
deployments, and tools of the database.
3. PyCharm also provides support to python web development
frameworks, JavaScript, HTML, CSS etc.
Cons.
1. PyCharm is an expensive tool
2. The initial installation is difficult and may hang up in between
sometimes.
(SPYDER)IT IS FAMOUS FOR PYTHON DEVELOPMENT. IT WAS MAINLY
DEVELOPED FOR SCIENTISTS AND ENGINEERS TO PROVIDE A POWERFUL
SCIENTIFIC ENVIRONMENT FOR PYTHON
SPYDER
Pros.
1. It is a good IDE with syntax highlighting, auto code
completion feature
2. A developer can execute the code line by line or by the cell.
3. Can trace each step of the script execution smoothly.
Cons.
1. not capable of configuring which warning the developer
wants to disable.
2. Its performance reduces when too many plugins are invoked
at the same time.
JUPYTER NOTEBOOK
PYTHON IDENTIFIERS
▪ A Python identifier is a name used to identify a variable,
% within identifiers.
denote string literals, as long as the same type of quote starts and
ends the string.
▪ The triple quotes are used to span the string across multiple lines.
from the
https://www.python.org/downloads/
1)Mutable - A variable is mutable if its value can be changed after creation. Examples of
mutable variables include lists, dictionaries, and sets.
2)Immutable - A variable is immutable if its value cannot be changed after creation. Examples
of immutable variables include int, float, bool, complex, strings, tuples, and sets.
i.Numbers
ii.Lists
Note : In python no need to define a
iii.Tuple variable as in like other programming
languages (C/C++), and there is no data
iv.Dictionary type for variable.
v.Strings
NUMBERS
▪ int Ex: var = 25
▪ long var = 12345678912
▪ float var = 1.2
▪ complex var = 1j
▪ bool var = True or False
Strings
▪ Strings can be represent by using single quotes or double quotes.
▪ ex : "String" or 'string'.
▪ Syntax :
var = datatype(var)
10. >>>print(c) → 12
2. >>> b = 2
→8 15. >>> a %= 5
7. >>>> print(b**3)
b = 20
if ( a is b):
print “Both are same"
else:
print “Both are not same"
Ex2:
a = 10
b = 20
if ( a is not b ):
print “Both are not same"
else:
print “Both are same"
DIFFERENCE BETWEEN IS AND ==
Parameters is Operator == Operator
→ 10 12 & 10 →8
2. 12 and 10 8.
3. 0 or 12 → 12 9. 0 ^ 12 → 12
2. Guido van Rossum and Fred L. Drake Jr, ―An Introduction to Python – Revised and updated for Python 3.2, Network Theory Ltd.,
2011.
3. John V Guttag, ―Introduction to Computation and Programming Using Python‘‘, Revised and expanded Edition, MIT Press , 2013
4. Robert Sedgewick, Kevin Wayne, Robert Dondero, ―Introduction to Programming in Python: An Inter-disciplinary Approach,
5. Timothy A. Budd, ―Exploring Python‖, Mc-Graw Hill Education (India) Private Ltd.,, 2015.
7. Charles Dierbach, ―Introduction to Computer Science using Python: A Computational ProblemSolving Focus, Wiley India
Edition, 2013.
8. Paul Gries, Jennifer Campbell and Jason Montojo, ―Practical Programming: An Introduction to Computer Science using Python