Python 45
Python 45
Python 45
• What is Python…?
• Differences between program 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(Variable, Strings, Data types etc.)
1
What is Python…?
• Python is a general purpose programming language that is
often applied in scripting roles.
• So, Pythonis programming language as
well as scripting language.
• Python is also called as Interpreted language
2
Differences between program
and scripting language
Program Scripting
•a program is •a script is interpreted
executed (i.e. the •A "script" is code
source is first
compiled, and the written in a scripting
result of that language. A scripting
compilation is language is nothing
expected) but a type of
•A "program" in programming
general, is a language in which we
sequence of can write code to
instructions written control
so that a computer another software 3
History
• Invented in the Netherlands, early 90s by Guido
van Rossum
• Python was conceived in the late 1980s
and its implementation was started in December
1989
• Guido Van Rossum is fan of ‘Monty
Python’s Flying Circus’, this is a famous TV show in
Netherlands
• Named after Monty Python
• Open sourced from the beginning
4
Python’s Benevolent Dictator For
Life
“Python is an experiment in how
much freedom programmers need.
Too much freedom and nobody can
read another's code; too little and
expressiveness is endangered.”
- Guido van Rossum
5
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.
I realized that the development of
administration
system utilities in was taking long
M
C oreover, doing these too in the .
wouldn't
things work for a variety of reasons.Bourne
... shel
So, there was a need for a l
language that would bridge the gap between C
and the shell”
- Guido Van Rossum
6
Scope of Python
• Science
- Bioinformatics
• System Administration
-Unix
-Web logic
-Web sphere
• Web Application
Development
-CGI
-Jython – Servlets
• Testing scripts
7
What can I do with Python…?
• System programming
• Graphical User Interface Programming
• Internet Scripting
• Component Integration
• Database Programming
• Gaming, Images, XML , Robot and more
8
Who uses python today…
• Python is being applied in real revenue-generating
products by real companies. For instance:
• Google makes extensive use of Pythonin
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 serviceis
largely written in Python
9
Why do people use Python…?
The following primary factors cited by Python users
seem to be these:
•Python is object-oriented
Structure supports such concepts as polymorphism,
operation overloading, and multiple inheritance.
.
•It's free (open source)
Downloading and installing Python is free and easy
Source code is easily accessible
10
• It's powerful
- Dynamic typing
- Built-in types and tools
- Library utilities
- Third party utilities (e.g. Numeric, NumPy, SciPy)
- Automatic memory management
• It's portable
- Python runs virtually every major platform used today
- As long as you have a compatible Python interpreter
installed, Python programs will run in exactly the same
manner, irrespective of platform.
11
Installing Python
• Python is pre-installed on most Unix systems, including
Linux and MAC OS X
12
• After installing the
Python Ver#2.7.7, go to
start menu then click on
python 2.7 in that one
you can select python
(command line) it is
prompt with >>>
13
14
Running Python
Once you're inside the Python interpreter, type in commands at will.
•Examples:
>>> print 'Hello world' Hello world
15
Python Code Execution
• Python’s traditional runtime execution model: source code
you type is translated to byte code, which is then run by the
Python Virtual Machine. Your code is automatically
compiled, but then it is interpreted.
18
Math
Rule: If you want Python to answer in floats, you
have to talk to it in floats.
More operators:
divide: /
multiply: *
>>> print 3 * 12 36
>>> print 12 / 3 4
>>> print 11 / 3 3
>>> print 12.0 / 3.0 4.0
>>> print 11.0 / 3.0 3.66
19
Math
Practic
e:
>>> print 2 < 3 True
>>> print 2 <= 2 False
>>> print 3 > 2 True
>>> print 2 != 3 True
>>> print False < True True
20
STRINGS IN
PYTHON
21
Strings
>>> “It’s a beautiful
Examples:
day!”
>>> “Goodbye, cruel
Try typing one without
world.”
quotes: What’s the result?
>>> Aggies
>>> “Aggies”
>>> “Rice fight, never
die!”
>>> “3 + 2” 22
Strings
String
operators:
concatenation:
+
multiplication: *
Try >>> print “Hello” +
concatenating: “ “ + “world!”
Try multiplying: >>> print “HAHA” *
250
23
VARIABLES IN
PYTHON
24
Variabl
e
Create a Variable:
>>>headmaster=“Dumble
dore”
>>>print headmaster
‘Dumbledore’
Assigning a New
Value:
>>>headmaster=“Hardcas
tle”
>>>print headmaster
‘Hardcastle’
25
DATA TYPES
IN PYTHON
Data
Type:
Python has many native data types. Here are the important ones:
27
Example:
String
“Whoop!”
Intege
42
r
3.14159
Float
[“John”, “Paul”,
List “George”, “Ringo”]
Python can tell us about types using the
type() function:
28
LIST: DATA
TYPE
29
List
:
The list is a most versatile Data type available in
Python which can be written as a list of comma-
separated values (items) between square brackets.
Important thing about a list is that items in a list
need not be of the same type.
Example:
list1 = ['physics', 'chemistry', 1997,
2000];
list2 = [1, 2, 3, 4, 5 ];
30
SN Function with Description
>>> type(Beatles)
>>> type(grades)
32
Lists
Index: Where an
item is in the list
Example:
tup2 = (1, 2, 3, 4, 5 );
tup3 = ("a", "b", "c", "d“);
35
Built-in Tuple Functions
Python includes the following tuple functions
−
SN Function with Description
36
LOOPS &
CONDITIONAL
STATEMENTS
37
Loop Type Description
nested loops You can use one or more loop inside any
another while, for or do..while loop.
3
9
Statement Description
39
I believe the trial has shown conclusively that it is both possible and desirable to
use Python as the principal teaching language:
40
42