The document discusses object-oriented programming concepts in Python like classes, objects, inheritance and polymorphism.
Some key points:
- Classes define the structure and behavior of an object using methods and attributes.
- Objects are instances of a class that contain data and allow methods to operate on that data.
- Inheritance allows a derived/child class to inherit attributes and methods from a base/parent class. The derived class can override or extend the parent class.
- Polymorphism allows derived classes to define their own implementation of a method while reusing the parent's implementation.
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAMaulik Borsaniya
Classes and Object-oriented Programming:
Classes: Creating a Class, The Self Variable, Constructor, Types of Variables, Namespaces, Types of Methods (Instance Methods, Class Methods, Static Methods), Passing Members of One Class to Another Class, Inner Classes
Inheritance and Polymorphism: Constructors in Inheritance, Overriding Super Class Constructors and Methods, The super() Method, Types of Inheritance, Single Inheritance, Multiple Inheritance, Method Resolution Order (MRO), Polymorphism, Duck Typing Philosophy of Python, Operator Overloading, Method Overloading, Method Overriding
Abstract Classes and Interfaces: Abstract Method and Abstract Class, Interfaces in Python, Abstract Classes vs. Interfaces,
Inheritance and Polymorphism in Python. Inheritance is a mechanism which allows us to create a new class – known as child class – that is based upon an existing class – the parent class, by adding new attributes and methods on top of the existing class.
در این جلسه به بررسی بحث برنامه نویسی شی گرا و کلاس ها در پایتون پرداختیم
PySec101 Fall 2013 J7E1 By Mohammad Reza Kamalifard
Talk About:
Object oriented programming and Classes in Python
A class is a code template for creating objects. Objects have member variables and have behaviour associated with them. In python a class is created by the keyword class.
An object is created using the constructor of the class. This object will then be called the instance of the class.
PYTHON-Chapter 3-Classes and Object-oriented Programming: MAULIK BORSANIYAMaulik Borsaniya
Classes and Object-oriented Programming:
Classes: Creating a Class, The Self Variable, Constructor, Types of Variables, Namespaces, Types of Methods (Instance Methods, Class Methods, Static Methods), Passing Members of One Class to Another Class, Inner Classes
Inheritance and Polymorphism: Constructors in Inheritance, Overriding Super Class Constructors and Methods, The super() Method, Types of Inheritance, Single Inheritance, Multiple Inheritance, Method Resolution Order (MRO), Polymorphism, Duck Typing Philosophy of Python, Operator Overloading, Method Overloading, Method Overriding
Abstract Classes and Interfaces: Abstract Method and Abstract Class, Interfaces in Python, Abstract Classes vs. Interfaces,
Inheritance and Polymorphism in Python. Inheritance is a mechanism which allows us to create a new class – known as child class – that is based upon an existing class – the parent class, by adding new attributes and methods on top of the existing class.
در این جلسه به بررسی بحث برنامه نویسی شی گرا و کلاس ها در پایتون پرداختیم
PySec101 Fall 2013 J7E1 By Mohammad Reza Kamalifard
Talk About:
Object oriented programming and Classes in Python
A class is a code template for creating objects. Objects have member variables and have behaviour associated with them. In python a class is created by the keyword class.
An object is created using the constructor of the class. This object will then be called the instance of the class.
Vision academe Pune is a leading institute in Pune conducting training programs for various software fields & provides certification for both individuals and organizations.Training Institute Pune is subsidiary of Optimized Infotech which offers IT services and training.
Learn how to use advanced web development concepts like OO and MVC in PHP. Project-focused demos and labs using your tool stack and environment More coding than lecture, coupled with architectural and design discussions.
Vision Academy is a well known Computer Training Institute in Hadapsar Pune from 2005.This institute was started by its visionary director Mr Sachin Zurange. Mr Sachin Zurange was completed MSc(Scientific Computing) From Interdisciplinary School Of Scientific Computing, University of Pune. It also clear SET exam in May 2018. We provides BCS, BCA, BBA(Comp.App), MCS, MCA, Dip(Comp), BE(Comp/IT) Coaching Classes in Hadapsar Pune. We mainly impart training in programming languages C,C++, Java, Advanced Java, Php, Phyton, .NET,HTML, Java Script, jQuery, Angular Js. Database Languages such as Oracle, Postgres, Mysql, SQL Server & focus on key subjects like Data Structure, Operating System,Rdbms. We provides career oriented programs in Web Design, WordPress, Digital Marketing courses. More then 10,000 students was trained from Vision Academy. We provide 100% practical oriented training program with 100% job placement.
Learn PHP fundamentals online at your own pace. Start today and improve your skills. Join millions of learners from around the world already learning on Udemy. Lifetime access. 204,000+ online courses. Millions of learners. 30-day guarantee. Real-world experts.
import in python is similar to #include header_file in C/C++. Python modules can get access to code from another module by importing the file/function using import. The import statement is the most common way of invoking the import machinery, but it is not the only way. import module_name .When the import is used, it searches for the module initially in the local scope by calling __import__() function. The value returned by the function is then reflected in the output of the initial code.
Vision academe Pune is a leading institute in Pune conducting training programs for various software fields & provides certification for both individuals and organizations.Training Institute Pune is subsidiary of Optimized Infotech which offers IT services and training.
Learn how to use advanced web development concepts like OO and MVC in PHP. Project-focused demos and labs using your tool stack and environment More coding than lecture, coupled with architectural and design discussions.
Vision Academy is a well known Computer Training Institute in Hadapsar Pune from 2005.This institute was started by its visionary director Mr Sachin Zurange. Mr Sachin Zurange was completed MSc(Scientific Computing) From Interdisciplinary School Of Scientific Computing, University of Pune. It also clear SET exam in May 2018. We provides BCS, BCA, BBA(Comp.App), MCS, MCA, Dip(Comp), BE(Comp/IT) Coaching Classes in Hadapsar Pune. We mainly impart training in programming languages C,C++, Java, Advanced Java, Php, Phyton, .NET,HTML, Java Script, jQuery, Angular Js. Database Languages such as Oracle, Postgres, Mysql, SQL Server & focus on key subjects like Data Structure, Operating System,Rdbms. We provides career oriented programs in Web Design, WordPress, Digital Marketing courses. More then 10,000 students was trained from Vision Academy. We provide 100% practical oriented training program with 100% job placement.
Learn PHP fundamentals online at your own pace. Start today and improve your skills. Join millions of learners from around the world already learning on Udemy. Lifetime access. 204,000+ online courses. Millions of learners. 30-day guarantee. Real-world experts.
import in python is similar to #include header_file in C/C++. Python modules can get access to code from another module by importing the file/function using import. The import statement is the most common way of invoking the import machinery, but it is not the only way. import module_name .When the import is used, it searches for the module initially in the local scope by calling __import__() function. The value returned by the function is then reflected in the output of the initial code.
Model Attribute Check Company Auto PropertyCeline George
In Odoo, the multi-company feature allows you to manage multiple companies within a single Odoo database instance. Each company can have its own configurations while still sharing common resources such as products, customers, and suppliers.
The Roman Empire A Historical Colossus.pdfkaushalkr1407
The Roman Empire, a vast and enduring power, stands as one of history's most remarkable civilizations, leaving an indelible imprint on the world. It emerged from the Roman Republic, transitioning into an imperial powerhouse under the leadership of Augustus Caesar in 27 BCE. This transformation marked the beginning of an era defined by unprecedented territorial expansion, architectural marvels, and profound cultural influence.
The empire's roots lie in the city of Rome, founded, according to legend, by Romulus in 753 BCE. Over centuries, Rome evolved from a small settlement to a formidable republic, characterized by a complex political system with elected officials and checks on power. However, internal strife, class conflicts, and military ambitions paved the way for the end of the Republic. Julius Caesar’s dictatorship and subsequent assassination in 44 BCE created a power vacuum, leading to a civil war. Octavian, later Augustus, emerged victorious, heralding the Roman Empire’s birth.
Under Augustus, the empire experienced the Pax Romana, a 200-year period of relative peace and stability. Augustus reformed the military, established efficient administrative systems, and initiated grand construction projects. The empire's borders expanded, encompassing territories from Britain to Egypt and from Spain to the Euphrates. Roman legions, renowned for their discipline and engineering prowess, secured and maintained these vast territories, building roads, fortifications, and cities that facilitated control and integration.
The Roman Empire’s society was hierarchical, with a rigid class system. At the top were the patricians, wealthy elites who held significant political power. Below them were the plebeians, free citizens with limited political influence, and the vast numbers of slaves who formed the backbone of the economy. The family unit was central, governed by the paterfamilias, the male head who held absolute authority.
Culturally, the Romans were eclectic, absorbing and adapting elements from the civilizations they encountered, particularly the Greeks. Roman art, literature, and philosophy reflected this synthesis, creating a rich cultural tapestry. Latin, the Roman language, became the lingua franca of the Western world, influencing numerous modern languages.
Roman architecture and engineering achievements were monumental. They perfected the arch, vault, and dome, constructing enduring structures like the Colosseum, Pantheon, and aqueducts. These engineering marvels not only showcased Roman ingenuity but also served practical purposes, from public entertainment to water supply.
The French Revolution, which began in 1789, was a period of radical social and political upheaval in France. It marked the decline of absolute monarchies, the rise of secular and democratic republics, and the eventual rise of Napoleon Bonaparte. This revolutionary period is crucial in understanding the transition from feudalism to modernity in Europe.
For more information, visit-www.vavaclasses.com
Unit 8 - Information and Communication Technology (Paper I).pdfThiyagu K
This slides describes the basic concepts of ICT, basics of Email, Emerging Technology and Digital Initiatives in Education. This presentations aligns with the UGC Paper I syllabus.
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
Synthetic fiber production is a fascinating and complex field that blends chemistry, engineering, and environmental science. By understanding these aspects, students can gain a comprehensive view of synthetic fiber production, its impact on society and the environment, and the potential for future innovations. Synthetic fibers play a crucial role in modern society, impacting various aspects of daily life, industry, and the environment. ynthetic fibers are integral to modern life, offering a range of benefits from cost-effectiveness and versatility to innovative applications and performance characteristics. While they pose environmental challenges, ongoing research and development aim to create more sustainable and eco-friendly alternatives. Understanding the importance of synthetic fibers helps in appreciating their role in the economy, industry, and daily life, while also emphasizing the need for sustainable practices and innovation.
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdfTechSoup
In this webinar you will learn how your organization can access TechSoup's wide variety of product discount and donation programs. From hardware to software, we'll give you a tour of the tools available to help your nonprofit with productivity, collaboration, financial management, donor tracking, security, and more.
2024.06.01 Introducing a competency framework for languag learning materials ...Sandy Millin
http://sandymillin.wordpress.com/iateflwebinar2024
Published classroom materials form the basis of syllabuses, drive teacher professional development, and have a potentially huge influence on learners, teachers and education systems. All teachers also create their own materials, whether a few sentences on a blackboard, a highly-structured fully-realised online course, or anything in between. Despite this, the knowledge and skills needed to create effective language learning materials are rarely part of teacher training, and are mostly learnt by trial and error.
Knowledge and skills frameworks, generally called competency frameworks, for ELT teachers, trainers and managers have existed for a few years now. However, until I created one for my MA dissertation, there wasn’t one drawing together what we need to know and do to be able to effectively produce language learning materials.
This webinar will introduce you to my framework, highlighting the key competencies I identified from my research. It will also show how anybody involved in language teaching (any language, not just English!), teacher training, managing schools or developing language learning materials can benefit from using the framework.
11. you must specify self explicitly when defining the method, you don’t
include it when calling the method
12.
13.
14. Classes are defined using keyword “Class”
followed by user defined “ClassName” and a
colon.
Variables are also called attributes
Functions are also called methods.
Syntax: class className:
<statement-1>
<statement-2>
;
<statement-n>
15. class Mobile:
def __init__(self, name):
self.mobile_name=name
print("Constructor")
def receive_msg(self):
print(f"Receive Message from {self.mobile_name}")
def send_msg(self):
print(f"Send Message from {self.mobile_name}")
def main():
nokia = Mobile("Nokia")
nokia.receive_msg()
nokia.send_msg()
if __name__=="__main__":
main()
Output:
Constructor
Receive Message from Nokia
Send Message from Nokia
•Class Mobile has 2 methods:
-Receive_msg()
- Send_msg()
•Self has no meaning in Python.
•It is used to improve readability.
•__init__ function is called when an
object is instantiated
16. Object refers to a particular instance of a class.
It contains variables and methods defined in the class.
Class objects support 2 kinds of operations.
◦ A. Attribute references – The names in class are referenced by
objects and are called attribute references. There are two
kinds of attribute references.
A. Data attributes – Variables defined within methods are called
instance variables / data attributes which are used to store data.
B. Method attributes – Functions that are inside a class and are
referenced by objects of a class.
B. Instantiation – Act of creating an object from a class.
17. class student:
def __init__(self,name,marks):
self.name = name
self.marks = marks
def check_pass_fail(self):
if self.marks >= 40:
return True
else:
return False
def main():
student1 = student("Harry", 30)
student2 = student("Jane", 99)
did_pass = student1.check_pass_fail()
print(did_pass)
did_pass = student2.check_pass_fail()
print(did_pass)
if __name__=="__main__":
main()
•Student1 and Student2 are the objects of
Student Class.
•Student1 is instantiated with name as Harry
and marks 30
•Student2 is instantiated with name as Jane
and marks 99
•Whenever you call a method using an object,
the object is automatically passed in as the
first parameter to the self parameter variable
Output
False
True
18. class Birds:
def __init__(self, bird_name):
self.bird_name = bird_name
def flying_birds(self):
print(f"{self.bird_name} flies above clouds")
def non_flying_birds(self):
print(f"{self.bird_name} is the national bird of Australia")
def main():
vulture=Birds("Griffon Vulture")
Crane = Birds("Common Crane")
Emu = Birds("Emu")
vulture.flying_birds()
Crane.flying_birds()
Emu.non_flying_birds()
if __name__=="__main__":
main()
Output:
Griffon Vulture flies above clouds
Common Crane flies above clouds
Emu is the national bird of Australia
vulture, Crane and Emu are the objects
of class Birds
19. Only one constructor can be defined per class
Syntax:
def __init__(self,parameter_1,….parameter_n)
It defines and initializes the instance variables
It is called as soon as an object of a class is
instantiated.
All the data attributes of a class are initialised
in the init function itself.
20. An object can be passed as an argument to a calling
function
class Music:
def __init__(self,song,artist):
self.song=song
self.artist=artist
def print_track_info(vocalist):
print(f"Song is {vocalist.song}")
print(f"Artist is {vocalist.artist}")
singer = Music("Boy With Love","BTS")
print_track_info(singer)
Output:
Song is Boy With Love
Artist is BTS2
21. class sum:
def __init__(self,num1,num2):
self.num1 = num1
self.num2 = num2
self.sum =" "
def add_sum(self):
self.sum = self.num1 + self.num2
return self
def main():
number =sum(4,5)
returned_object = number.add_sum()
print(returned_object.sum)
print(id(returned_object))
print(isinstance(returned_object,sum))
if __name__=="__main__":
main()
Output:
9
1787802679712
True
•id(object) is a function that is used to find
the identity of the location of the object in
memory
•Isinstance(object,classinfo) is a function
that returns a boolean stating if the object
is an instance of class or not.
22. class Dog:
kind ='Canine'
def __init__(self,name):
self.dog_name=name
d=Dog('Fido')
e=Dog("Buddy")
print(f"{d.kind}")
print(f"{e.kind}")
print(f"{d.dog_name}")
print(f"{e.dog_name}")
Output:
Canine
Canine
Fido
Buddy
Class Attributes:
Are Class variables that is
shared by all objects of a
class.
Data Attributes
Are instance variables
unique to each object of a
class.
23. Encapsulation -> Information hiding
Abstraction -> Implementation hiding
It is the process of combining variables that store data and
methods that work on those variables into a single unit called
class.
class foo:
def __init__(self,a,b):
self.a = a
self.b = b
def add(self):
return self.a + self.b
foo_object =foo(3,4)
print(foo_object.add())
Output:
7
The internal representation of the foo
class is hidden outside the class ->
Encapsulation
The implementation of add() function
is hidden from the object. ->
Abstraction
24. class Demo:
def __init__(self):
self.nonprivate="I am not a private instance"
self.__private="I am a private instance"
def display_privateinstance(self):
print(f"{self.__private} used within the method of a class")
def main():
demo_obj = Demo()
demo_obj.display_privateinstance()
print(demo_obj.nonprivate)
# print(demo_obj.__private)
if __name__=="__main__":
main()
Output:
I am a private instance used within
the method of a class
I am not a private instance
25. The private instance variables cannot be accessed outside the
class, but only through a method defined inside the class
In Python, an identifier with double underscore is treated as
private.
Name mangling is intended to give the class an easy way to
define private instance variables and methods
class Student:
def __init__(self, name):
self.__name = name // private attribute
s1 = Student("Santa")
print(s1._Student__name)
//Access using _class__private attribute
26. The class that is used as the basis for inheritance is called
a superclass or base class.
A class that inherits from a base class is called a subclass
or derived class.
The base class and derived class exhibit “is a” relationship
in inheritance
Eg: Sitar is a stringed instrument
Syntax of derived class:
Class DerivedClassName(BaseClassName):
<statement-1>
.
.
<statement-N>
27. It is possible to define the derived base when the base class is defined in another module.
Class DerivedClassName(modname.BaseClassName)
# module1.py
class Hello:
def show(self):
print("Module1.Hello.Show Welcome")
#modulederived.py
____________________________________________________________________________________________________
import module1
class derived_module1(module1.Hello): # derived class of the Hello class in Module 1
def derived_class(self):
print("Hi")
def main():
check = derived_module1() # object of the derived_module1 class
check.show()
if __name__=="__main__":
main()
Output:
Module1.Hello.Show Welcome
28. class someclass(object): # this is derived out of the "class object"
def __init__(self):
print("Constructor")
def someclass_function(self):
print("Hello India")
def main():
obj = someclass()
obj.someclass_function()
if __name__=="__main__":
main()
•All class except “Class object” are
derived classes.
•Class object is the base of
inheritance hierarchy and hence
has no derived classes.
•Classes without baseclassname are
derived from the class object.
29. class cricket:
def __init__(self,IPLteam,owner,times_won):
self.IPLteam = IPLteam
self.owner = owner
self.times_won = times_won
def IPLOwner(self):
print(f"The IPL team {self.IPLteam} is owned by {self.owner}")
class derived_cricket(cricket):
def IPLresults(self):
print(f"The IPL team {self.IPLteam} has won {self.times_won}")
def main():
cricket_fans=derived_cricket("KKR","SRK", 9)
cricket_fans.IPLOwner()
cricket_fans.IPLresults()
if __name__=="__main__":
main()
Output:
The IPL team KKR is
owned by SRK
The IPL team KKR has
won 9
30. Derived_cricket is the derived class and cricket is the base
class
Derived class inherits variables and methods of base class
__init__() method is also derived from base class. Derived
class has access of __init__() method of the base class.
The base class has 3 data attributes, IPLteam, owner and
times_won. It has a method IPLOwner
Derived class has access to the data attributes and methods
of the base class.
31. In Single Inheritance, built-in super() function is used to refer
to base class without explicitly naming it.
If derived class has __init__() method and needs to access the
base class __init__() method explicitly, then this is done using
super().
If the derived class needs no attributes from base class, then
we do not need to use super() method to invoke base class
__init__() method.
Super().__init__(base_class_parameters)
32. Its usage is as below.
Class DerivedClass(BaseClass):
def__init__(self, derived_class_params, base_class_params)
super().__init__(base_class_params)
self.derived_class_params = derived_class_params
The derived class __init__() method has its own parameters
plus the base class parameters.
We do not need to specify self for base class init() method
Base class methods may be overridden (method overriding)
Derived class should have a method with same name as those
in base class. Also signature (method name, order and total
number of parameters) should be same.
33. class country:
def __init__(self,country_name):
self.country_name = country_name
def country_details(self):
print(f"Happiest country in world is {self.country_name}")
class HappyCountry(country):
def __init__(self,country_name,continent):
super().__init__(country_name)
self.continent = continent
def Happy_Country_Details(self):
print(f"Happiest country in the world is {self.country_name} and it is in {self.continent}")
def main():
obj = HappyCountry("Finland","Europe")
obj.Happy_Country_Details()
if __name__=="__main__":
main()
Output:
Happiest country in the world
is Finland and it is in Europe