2. 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
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)
5. 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/
6. 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
7. APPLICATIONS
• Web and Internet Development
• Scientific and Numeric computing
• Software Development
• GUI Development
• Rapid Prototyping
• Writing Scripts
• Data Analysis
8. PROGRAM STRUCTURE
• Similar to other Object oriented programming
languages
• Importing libraries
• Initializing Variables
• Initializing Classes and Objects
• Structured with indentations
12. 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
13. 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
14. 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"""
15. 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']
16. 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')
17. 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' }
18. 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
19. 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".
21. 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
22. 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!
24. 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
25. 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
26. 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
27. 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
28. 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
29. 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.
33. 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
34. 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”
35. 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