PROJECT
PRESENTATIONby Diwakar raja
HISTORY
• Python was conceived in the late 1980’s by Guido
van Rossum
• Developed at Centrum Wiskunde & Informatica in
the Netherlands
• Influenced by ABC programming language,
MODULA 2+ and MODULA 3
VERSIONS
• The first public version of python was released on
February 20, 1991
• Version 1.0 (1994 - 2000)
• Version 2.0 (2000 - 2008)
• Version 3.0 (2008 - Present day)
PARADIGM /
CLASSIFICATION
• Python supports multiple paradigms
• More Object Oriented
• Imperative
• Functional
• Procedural
• Reflective
COMPILERS
• Python source code is automatically compiled when
you install python on your computer
• Mac OS, latest Linux distributions and UNIX comes
with python pre-installed
• Python can be downloaded from
https://www.python.org/downloads/
MORE COMPILERS
There are various compilers for various
implementations of python.
Few compilers for the default implementation
(Cpython) :
• Nuitka - http://nuitka.net/pages/download.html
• Pyjs - http://pyjs.org/Download.html
APPLICATIONS
• Web and Internet Development
• Scientific and Numeric computing
• Software Development
• GUI Development
• Rapid Prototyping
• Writing Scripts
• Data Analysis
PROGRAM STRUCTURE
• Similar to other Object oriented programming
languages
• Importing libraries
• Initializing Variables
• Initializing Classes and Objects
• Structured with indentations
DATA TYPES
• Numbers
• Boolean
• String
• Lists
• Tuples
• Dictionaries
NUMBERS
• Any number you enter in Python will be interpreted as a
number; you are not required to declare what kind of data type
you are entering
Type Format Description
int a=10 Signed integer
long a=345L Long integer
float a=45.67 Floating point real values
complex a=3.14J Real and imaginary values
BOOLEAN
• The Boolean data type can be one of two values,
either True or False
• We can declare them as following
y=True
z=False
• Another special data type we have to know about is none. It holds
no value and is declared as
x=none
STRING
• Create string variables by enclosing characters in quotes
Declared as:
firstName = 'john'
lastName = "smith"
message = """This is a string that will span across multiple lines.
Using newline characters and no spaces for the next lines.
The end of lines within this string also count as a newline when
printed"""
LISTS
• A list can contain a series of values. List variables are declared by using
brackets [] following the variable name.
# w is an empty list
w=[]
# x has only one member
x=[3.0]
# y is a list of numbers
y=[1,2,3,4,5]
# z is a list of strings and other lists
z=['first',[],'second',[1,2,3,4],'third']
TUPLE
• Tuples are a group of values like a list and are
manipulated in similar ways. But, tuples are fixed in size
once they are assigned. In Python the fixed size is
considered immutable as compared to a list that is
dynamic and mutable. Tuples are defined by parenthesis
().
Example:
myGroup = ('Rhino', 'Grasshopper', 'Flamingo', 'Bongo')
DICTIONARIES
• A Python dictionary is a group of key-value
pairs. The elements in a dictionary are
indexed by keys. Keys in a dictionary are
required to be unique.
Example:
words = { 'girl': 'Maedchen', 'house': 'Haus', 'death': 'Tod' }
USER DEFINED DATA
TYPES
Classes and Objects:
• Objects are an encapsulation of variables and functions into a
single entity.
• Objects get their variables and functions from classes.
• Classes are essentially a template to create your objects
CLASSES AND OBJECTS
Examples:
The variable "myobjectx" holds an object of the class "MyClass" that contains the variable
and the function defined within the class called "MyClass".
CLASSES AND OBJECTS
Examples:
To access a function inside of an object you use notation similar to accessing a variable
SEQUENCE CONTROL
• Expressions:
An expression is an instruction that combines values and
operators and always evaluates down to a single value.
For example, this is an expression:
2+2
• Statements:
A Python statement is pretty much everything else that isn't an expression.
Here's an assignment statement:
spam=2+2
IF STATEMENTS
Perhaps the most well-known statement type is the if stateme
For example:
if temp < 10:
print "It is cold!”
Output:
It is cold!
IF ELSE STATEMENTS
Example:
temp = 20
if temp < 10:
print "It is cold!"
else:
print "It feels good!”
Output:
It feels good!
FOR STATEMENTS
Python’s for statement iterates over the items of any sequence (a list
or a string), in the order that they appear in the sequence.
For example:
for i in [0,1,2,3,4]:
print i
Output:
0
1
2
3
4
WHILE LOOPS
A while loop repeats a sequence of statements until some condition become
For example:
x = 5
while x > 0:
print (x)
x = x – 1
Output:
5
4
3
2
1
BREAK STATEMENT
Python includes statements to exit a loop (either a for loop or
while loop) prematurely. To exit a loop, use the break stateme
x = 5
while x > 0:
print x
break
x = 1
print x
Output:
5
CONTINUE STATEMENT
The continue statement is used in a while or for loop to take the control to the
of the loop without executing the rest statements inside the loop. Here is a si
example.
for x in range(6):
if (x == 3 or x==6):
continue
print(x)
Output:
0
1
2
4
5
INPUT/OUTPUT
There will be situations where your program has to interact with the use
example, you would want to take input from the user and then print som
results back. We can achieve this using the input() function and print() f
respectively.
Example:
something = input("Enter text: “)
print(something)
Output:
Enter text: Sir
Sir
FILE INPUT/OUTPUT
Reading and Writing Text from a File:
In order to read and write a file, Python built-in
function open() is used to open the file. The open()function
creates a file object.
Syntax:
file object = open(file_name [, access_mode])
• First argument file_name represents the file name that
you want to access.
• Second argument access_mode determines, in which
mode the file has to be opened, i.e., read, write, append,
etc.
FILE INPUT
Example:
file_input = open("simple_file.txt",'r')
all_read = file_input.read()
print all_read
file_input.close()
Output:
Hello
Hi
FILE OUTPUT
Example:
text_file = open("writeit.txt",'w')
text_file.write("Hello")
text_file.write("Hi")
text_file.close()
SUB-PROGRAM CONTROL
abs() dict() help() min() setattr() chr() repr() round()
all() dir() hex() next() slice() type() compile() delattr()
any() divmod() id() object() sorted() list() globals() hash()
ascii() enumerate() input() oct()
staticmethod(
)
range() map() print()
bin() eval() int() open() str() vars() reversed() set()
bool() exec() isinstance() ord() sum() zip() max() float()
bytearray() filter() issubclass() pow() super()
classmethod(
)
complex() format()
Some built-in functions:
USER DEFINED
FUNCTIONS
A function is defined in Python by the following format:
def functionname(arg1, arg2, ...):
statement1
statement2
…
Example:
def functionname(arg1,arg2):
return arg1+ arg2
t = functionname(24,24) # Result: 48
ENCAPSULATION
• In an object oriented python program, you can restrict access to methods
and variables. This can prevent the data from being modified by accident
and is known as encapsulation.
• Instance variable names starting with two underscore characters cannot be
accessed from outside of the class.
Example:
class MyClass:
__variable = "blah"
def function(self):
print self.__variable
myobjectx = MyClass()
myobjectx.__variable #will give an error
myobjectx.function() #will output “blah”
INHERITANCE
Inheritance is used to inherit another class' members, including fields and
methods. A sub class extends a super class' members.
Example:
class Parent:
variable = "parent"
def function(self):
print self.variable
class Child(Parent):
variable2 = "blah"
childobjectx = Child()
childobjectx.function()
Output:
Parent
EXAMPLE PROGRAM
PROGRAMMING PROJECT
http://cs.newpaltz.edu/~anbarasd1/simple3/
APPLET

Presentation new

  • 1.
  • 2.
    HISTORY • Python wasconceived in the late 1980’s by Guido van Rossum • Developed at Centrum Wiskunde & Informatica in the Netherlands • Influenced by ABC programming language, MODULA 2+ and MODULA 3
  • 3.
    VERSIONS • The firstpublic version of python was released on February 20, 1991 • Version 1.0 (1994 - 2000) • Version 2.0 (2000 - 2008) • Version 3.0 (2008 - Present day)
  • 4.
    PARADIGM / CLASSIFICATION • Pythonsupports multiple paradigms • More Object Oriented • Imperative • Functional • Procedural • Reflective
  • 5.
    COMPILERS • Python sourcecode is automatically compiled when you install python on your computer • Mac OS, latest Linux distributions and UNIX comes with python pre-installed • Python can be downloaded from https://www.python.org/downloads/
  • 6.
    MORE COMPILERS There arevarious compilers for various implementations of python. Few compilers for the default implementation (Cpython) : • Nuitka - http://nuitka.net/pages/download.html • Pyjs - http://pyjs.org/Download.html
  • 7.
    APPLICATIONS • Web andInternet Development • Scientific and Numeric computing • Software Development • GUI Development • Rapid Prototyping • Writing Scripts • Data Analysis
  • 8.
    PROGRAM STRUCTURE • Similarto other Object oriented programming languages • Importing libraries • Initializing Variables • Initializing Classes and Objects • Structured with indentations
  • 11.
    DATA TYPES • Numbers •Boolean • String • Lists • Tuples • Dictionaries
  • 12.
    NUMBERS • Any numberyou enter in Python will be interpreted as a number; you are not required to declare what kind of data type you are entering Type Format Description int a=10 Signed integer long a=345L Long integer float a=45.67 Floating point real values complex a=3.14J Real and imaginary values
  • 13.
    BOOLEAN • The Booleandata type can be one of two values, either True or False • We can declare them as following y=True z=False • Another special data type we have to know about is none. It holds no value and is declared as x=none
  • 14.
    STRING • Create stringvariables by enclosing characters in quotes Declared as: firstName = 'john' lastName = "smith" message = """This is a string that will span across multiple lines. Using newline characters and no spaces for the next lines. The end of lines within this string also count as a newline when printed"""
  • 15.
    LISTS • A listcan contain a series of values. List variables are declared by using brackets [] following the variable name. # w is an empty list w=[] # x has only one member x=[3.0] # y is a list of numbers y=[1,2,3,4,5] # z is a list of strings and other lists z=['first',[],'second',[1,2,3,4],'third']
  • 16.
    TUPLE • Tuples area group of values like a list and are manipulated in similar ways. But, tuples are fixed in size once they are assigned. In Python the fixed size is considered immutable as compared to a list that is dynamic and mutable. Tuples are defined by parenthesis (). Example: myGroup = ('Rhino', 'Grasshopper', 'Flamingo', 'Bongo')
  • 17.
    DICTIONARIES • A Pythondictionary is a group of key-value pairs. The elements in a dictionary are indexed by keys. Keys in a dictionary are required to be unique. Example: words = { 'girl': 'Maedchen', 'house': 'Haus', 'death': 'Tod' }
  • 18.
    USER DEFINED DATA TYPES Classesand Objects: • Objects are an encapsulation of variables and functions into a single entity. • Objects get their variables and functions from classes. • Classes are essentially a template to create your objects
  • 19.
    CLASSES AND OBJECTS Examples: Thevariable "myobjectx" holds an object of the class "MyClass" that contains the variable and the function defined within the class called "MyClass".
  • 20.
    CLASSES AND OBJECTS Examples: Toaccess a function inside of an object you use notation similar to accessing a variable
  • 21.
    SEQUENCE CONTROL • Expressions: Anexpression is an instruction that combines values and operators and always evaluates down to a single value. For example, this is an expression: 2+2 • Statements: A Python statement is pretty much everything else that isn't an expression. Here's an assignment statement: spam=2+2
  • 22.
    IF STATEMENTS Perhaps themost well-known statement type is the if stateme For example: if temp < 10: print "It is cold!” Output: It is cold!
  • 23.
    IF ELSE STATEMENTS Example: temp= 20 if temp < 10: print "It is cold!" else: print "It feels good!” Output: It feels good!
  • 24.
    FOR STATEMENTS Python’s forstatement iterates over the items of any sequence (a list or a string), in the order that they appear in the sequence. For example: for i in [0,1,2,3,4]: print i Output: 0 1 2 3 4
  • 25.
    WHILE LOOPS A whileloop repeats a sequence of statements until some condition become For example: x = 5 while x > 0: print (x) x = x – 1 Output: 5 4 3 2 1
  • 26.
    BREAK STATEMENT Python includesstatements to exit a loop (either a for loop or while loop) prematurely. To exit a loop, use the break stateme x = 5 while x > 0: print x break x = 1 print x Output: 5
  • 27.
    CONTINUE STATEMENT The continuestatement is used in a while or for loop to take the control to the of the loop without executing the rest statements inside the loop. Here is a si example. for x in range(6): if (x == 3 or x==6): continue print(x) Output: 0 1 2 4 5
  • 28.
    INPUT/OUTPUT There will besituations where your program has to interact with the use example, you would want to take input from the user and then print som results back. We can achieve this using the input() function and print() f respectively. Example: something = input("Enter text: “) print(something) Output: Enter text: Sir Sir
  • 29.
    FILE INPUT/OUTPUT Reading andWriting Text from a File: In order to read and write a file, Python built-in function open() is used to open the file. The open()function creates a file object. Syntax: file object = open(file_name [, access_mode]) • First argument file_name represents the file name that you want to access. • Second argument access_mode determines, in which mode the file has to be opened, i.e., read, write, append, etc.
  • 30.
    FILE INPUT Example: file_input =open("simple_file.txt",'r') all_read = file_input.read() print all_read file_input.close() Output: Hello Hi
  • 31.
    FILE OUTPUT Example: text_file =open("writeit.txt",'w') text_file.write("Hello") text_file.write("Hi") text_file.close()
  • 32.
    SUB-PROGRAM CONTROL abs() dict()help() min() setattr() chr() repr() round() all() dir() hex() next() slice() type() compile() delattr() any() divmod() id() object() sorted() list() globals() hash() ascii() enumerate() input() oct() staticmethod( ) range() map() print() bin() eval() int() open() str() vars() reversed() set() bool() exec() isinstance() ord() sum() zip() max() float() bytearray() filter() issubclass() pow() super() classmethod( ) complex() format() Some built-in functions:
  • 33.
    USER DEFINED FUNCTIONS A functionis defined in Python by the following format: def functionname(arg1, arg2, ...): statement1 statement2 … Example: def functionname(arg1,arg2): return arg1+ arg2 t = functionname(24,24) # Result: 48
  • 34.
    ENCAPSULATION • In anobject oriented python program, you can restrict access to methods and variables. This can prevent the data from being modified by accident and is known as encapsulation. • Instance variable names starting with two underscore characters cannot be accessed from outside of the class. Example: class MyClass: __variable = "blah" def function(self): print self.__variable myobjectx = MyClass() myobjectx.__variable #will give an error myobjectx.function() #will output “blah”
  • 35.
    INHERITANCE Inheritance is usedto inherit another class' members, including fields and methods. A sub class extends a super class' members. Example: class Parent: variable = "parent" def function(self): print self.variable class Child(Parent): variable2 = "blah" childobjectx = Child() childobjectx.function() Output: Parent
  • 36.
  • 37.
  • 38.