Object Oriented Programming Using Python: Name:Ankeet Giri Reg No.: 11904096

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 20

Object Oriented Programming

using Python

Name :Ankeet Giri


Reg no. : 11904096
What is Python ?
Python is an interpreted, object-oriented, high-
level programming language with dynamic
semantics. Its high-level built in data structures,
combined with dynamic typing and dynamic
binding, make it very attractive for Rapid
Application Development, as well as for use as a
scripting or glue language to connect existing
components together. Python's simple, easy to
learn syntax emphasizes readability and therefore
reduces the cost of program maintenance. Python
supports modules and packages, which
encourages program modularity and code reuse.
The Python interpreter and the extensive standard
library are available in source or binary form
without charge for all major platforms, and can
be freely distributed.
2
Features of Python

3
Uses of python
Software & SAAS products
To help technology and software driven companies with their software and Saas
product

IoT Solutions
Build solution to monitor , learn and capture insights from corrected devices

Mobile Web Solutions


Build customer end enterprise mobile app for customer engagement and
workforce productivity

Digital Application
Provide application service for a wide range of industries to build
and manage custom web , mobile and business solutions .
Why learn python?
 Fun-to-use "Scripting language“
 Object-oriented
 Highly educational
 Very easy to learn
 Powerful, scalable, easy to maintain
 high productivity
 Lots of libraries
 Glue language
 Interactive front-end for FORTRAN/C/C++ code

5
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 .
Source code extension is .py
Byte code extension is .pyc (compiled python code)

6
Variable and data types
Variable is the name given to an object, not to the memory location. Variables are nothing
but reserved memory locations to store values. This means that when we create a variable
we reserve some space in memory.
Create a Variable:
>>>headmaster = “Dumbledore”
>>>print headmaster
‘Dumbledore’
Assigning a New Value:
>>>headmaster = “Hardcastle”
>>>print headmaster
‘Hardcastle’
7
Rules for Python variables
1. A variable can have a short name (like x and y) or a more descriptive
name ( age, carname, total_volume) .
2. 2. A variable name must start with a letter or the underscore character.
3. 3. A variable name cannot start with a number.
4. 4. A variable name can only contain alpha-numeric characters and
underscores (A-z, 0-9, and _ ).
5. 5. Variable names are case-sensitive (age, Age and AGE are three
different variables).

8
Data Types
Variables can store data of different types, and different types can do different things.
Python has the following data types built-in by default, in these categories :
1) String - Strings are amongst the most popular types in Python. We can create them
simply by enclosing characters in quotes. Python treats single quotes the same as double
quotes. Creating strings is as simple as assigning a value to a variable, for example:
var1 = 'Hello World!’ , var2 = "Python Programming“
2) Int - They are often called just integers or int, are positive or negative whole numbers
with no decimal point, for example
var1 = 20
3) Float - they represent real numbers and are written with a decimal point dividing the
integer and fractional parts. Floats may also be in scientific notation, with E or
e indicating the power of 10 (2.5e2 = 2.5 x 102 = 250), for example
var1 = 20.3

9
4) List - The list is a most versatile datatype 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.
list1 = ['physics', 'chemistry', 1997, 2000];
list2 = [1, 2, 3, 4, 5];
5) Tuple - A tuple is a collection of objects which ordered and immutable. Tuples
are sequences, just like lists. The differences between tuples and lists are, the
tuples cannot be changed unlike lists and tuples use parentheses, whereas lists
use square brackets.
tup1 = ('physics', 'chemistry', 1997, 2000);
tup3 = "a", "b", "c", "d“
6) Dictionary - Each key is separated from its value by a colon (:), the items are
separated by commas, and the whole thing is enclosed in curly braces. An empty
dictionary without any items is written with just two curly braces, like this: {}.
Keys are unique within a dictionary while values may not be. The values of a
dictionary can be of any type, but the keys must be of an immutable data type
such as strings, numbers, or tuples. For example

10
dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'}
Operators in python
1.Arithmetic Operator 2.Relational Operator

11
3.Assignment 4. Logical operator
Operator

12
5. Identity 6.Bitwise Operator
Operator

13
Conditional Statement
1. If Statement 2. If –Else Statement

Syntax : Syntax :

if condition:
if condition : #block of statements
#Block of statement else:
print (statement); #another block of statements (else-
block)

14
3. Elif statement 4 . For loop
The syntax of the if-statement is: The syntax of for loop in python:

if expression 1: for iterating_var in sequence:


# Block of statements statement(s)
elif expression 2:
# Block of statements
elif expression 3:
# Block of statements
else:
# Block of statements

15
5 . While Loop 6 . Nested Loop

The syntax of while loop in The syntax of nested loop in python:


python:
for iterating_var in sequence:
while expression: for iterating_var in sequence:
statement(s) statements(s)
statements(s)

16
Functions in python
Python Functions is a block of related statements designed to perform a computational,
logical, or evaluative task.
There are mainly two types of functions:
1. User-define functions - The user-defined functions are those define by the user to
perform the specific task.
2. Built-in functions - The built-in functions are those functions that are pre-defined in
Python.

Function blocks begin with the keyword def followed by the function name and
parentheses ( ( ) ). Any input parameters or arguments should be placed within these
parentheses. You can also define parameters inside these parentheses. The first
statement of a function can be an optional statement - the documentation string of the
function or docstring. The code block within every function starts with a colon (:) and is
indented The statement return [expression] exits a function, optionally passing back an
expression to the caller. A return statement with no arguments is the same as return
17
none.
Introduction to Object Oriented
Programming

Python is a multi-paradigm programming language. It supports different programming


approaches. One of the finest approaches to solve a programming problem is by creating
objects which is known as Object Oriented Programming (OOP).
An object has two characteristics:
1. Attribute
2. Behaviour

We can take anything which has a name, age, and colour as its attributes and the things
which it does as behaviour.

18
Class : A class is like a blueprint for the object.
Object: An object (instance) is an instantiation of a class. When class is defined, only the
description for the object is defined. Therefore, no memory or storage is allocated.
Methods: Methods are functions defined inside the body of a class. They are used to define
the behaviours of an object
Inheritance: Inheritance is a way of creating a new class for using details of an existing
class without modifying it. The newly formed class is a derived class (or child class).
Similarly, the existing class is a base class (or parent class).
Encapsulation: Using OOP in Python, we can restrict access to methods and variables. This
prevents data from direct modification which is called encapsulation. In Python, we denote
private attributes using underscore as the prefix i.e., single _ or double
Polymorphism: Polymorphism is an ability (in OOP) to use a common interface for multiple
forms (data types). Suppose, we need to color a shape, there are multiple shape options
(rectangle, square, circle). However we could use the same method to color any shape. This
concept is called Polymorphism.
19
THANK YOU

20

You might also like