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.
Object oriented programming with pythonArslan Arshad
A short intro to how Object Oriented Paradigm work in Python Programming language. This presentation created for beginner like bachelor student of Computer Science.
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.
Object oriented programming with pythonArslan Arshad
A short intro to how Object Oriented Paradigm work in Python Programming language. This presentation created for beginner like bachelor student of Computer Science.
OOPS concepts are one of the most important concepts in high level languages. Here in this PPT we will learn more about Object oriented approach in python programming which includes details related to classes and objects, inheritance, dat abstraction, polymorphism and many more with examples and code.
This presentation deals with pure object oriented concepts and defines basic principles of OOP's like Encapsulation , polymorphism , Inheritance and Abstraction.
OOPS concepts are one of the most important concepts in high level languages. Here in this PPT we will learn more about Object oriented approach in python programming which includes details related to classes and objects, inheritance, dat abstraction, polymorphism and many more with examples and code.
This presentation deals with pure object oriented concepts and defines basic principles of OOP's like Encapsulation , polymorphism , Inheritance and Abstraction.
To better understand the behavior of servlets, let’s take a look at the life cycle of servlets.
A servlet is basically a small Java program that runs within a Web server. It can receive requests from clients and return responses. The whole life cycle of a servlet breaks up into 3 phases:
• Initialization: A servlet is first loaded and initialized usually when it is requested by the corresponding clients. Some websites allow the users to load and initialize servlets when the server is started up so that the first request will get responded more quickly.
• Service: After initialization, the servlets serve clients on request, implementing the ap- plication logic of the web application they belong to.
• Destruction: When all pending requests are processed and the servlets have been idle for a specific amount of time, they may be destroyed by the server and release all the resources they occupy.
More specifically, the behavior of a servlet is described in javax.servlet.Servlet interface, in which the following methods are defined:
• public void init(ServletConfig config) throws ServletException
This method is called once when the servlet is loaded into the servlet engine, before the servlet is asked to process its first request.
The init method has a ServletConfig parameter. The servlet can read its initialization arguments through the ServletConfig object. How the initialization arguments are set is servlet engine dependent but they are usually defined in a configuration file.
A typical example of an initialization argument is a database identifier. A servlet can read this argument from the ServletConfig at initialization and then use it later to open a connection to the database during processing of a request:
private String databaseURL;
public void init(ServletConfig config) throws ServletException { super.init(config);
databaseURL = config.getInitParameter("database");
}
• public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException
This method is called to process a request. It can be called zero, one or many times until the servlet is unloaded.
Once a servlet is loaded, it remains in the server’s memory as a single object instance. Thereafter, the server invokes the servlet to handle a request using a simple, lightweight method invocation. Unlike with CGI, there’s no process to spawn or interpreter to invoke, so the servlet can begin handling the request almost immediately. Multiple, concurrent requests are handled by separate threads, so servlets are highly scalable.
Servlets are naturally enduring objects. Because a servlet stays in the server’s memory as a single object instance, it automatically maintains its state and can hold on to external resources, such as database connections, that may otherwise take several seconds to establish. The following servlet presents information about how many times it has been accessed:
To better understand the behavior of servlets, let’s take a lo
Palestine last event orientationfvgnh .pptxRaedMohamed3
An EFL lesson about the current events in Palestine. It is intended to be for intermediate students who wish to increase their listening skills through a short lesson in power point.
Operation “Blue Star” is the only event in the history of Independent India where the state went into war with its own people. Even after about 40 years it is not clear if it was culmination of states anger over people of the region, a political game of power or start of dictatorial chapter in the democratic setup.
The people of Punjab felt alienated from main stream due to denial of their just demands during a long democratic struggle since independence. As it happen all over the word, it led to militant struggle with great loss of lives of military, police and civilian personnel. Killing of Indira Gandhi and massacre of innocent Sikhs in Delhi and other India cities was also associated with this movement.
Ethnobotany and Ethnopharmacology:
Ethnobotany in herbal drug evaluation,
Impact of Ethnobotany in traditional medicine,
New development in herbals,
Bio-prospecting tools for drug discovery,
Role of Ethnopharmacology in drug evaluation,
Reverse Pharmacology.
How to Create Map Views in the Odoo 17 ERPCeline George
The map views are useful for providing a geographical representation of data. They allow users to visualize and analyze the data in a more intuitive manner.
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
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.
2. Unit I
Programming and Computational
Thinking (PCT-2)
(80 Theory + 70 Practical)
DCSc & Engg, PGDCA,ADCA,MCA.MSc(IT),Mtech(IT),MPhil (Comp. Sci)
Department of Computer Science, Sainik School Amaravathinagar
Cell No: 9431453730
Praveen M Jigajinni
Prepared by
Courtesy CBSE
Class XII
4. INTRODUCTION
This chapter deals with classes in
Python. As Python is fully object-oriented,
you can define your own Classes, inherit
from your own or built-in classes, and
instantiate the classes that you've defined.
But before we start with our study on
classes let us understand about namespaces
and scope rules in Python.
6. These consist of functions such as max() ,
min() and built-in exception names. This
namespace is created when the Python
interpreter starts up, and is never deleted.
The built-in names actually also live in a
module called__ builtin__
1. BULIT IN NAMESPACE
7. The global namespace for a module is
created when the module definition is read in
and normally lasts until the interpreter quits.
The statements executed by the top-level
invocation of the interpreter, either read
from a script file or interactively, are
considered to be part of a module
called__main__ and they have their own
global namespace.
2. GLOBAL NAMES IN A MODULE
8. The global namespace for a module is
created when the module definition is read in
and normally lasts until the interpreter quits.
The statements executed by the top-level
invocation of the interpreter, either read
from a script file or interactively, are
considered to be part of a module
called__main__ and they have their own
global namespace.
3. LOCAL NAMES IN A FUNCTION INVOCATION
9. The local namespace for a function is
created when the function is called, and
deleted when the function returns or raises
an exception that is not handled within the
function. Even each recursive invocation has
its own local namespace.
3. LOCAL NAMES IN A FUNCTION INVOCATION
10. The local namespace for a function is
created when the function is called, and
deleted when the function returns or raises
an exception that is not handled within the
function. Even each recursive invocation has
its own local namespace.
If we talk about classes and objects, the set
of attributes of an object also form a
namespace.
contd…
3. LOCAL NAMES IN A FUNCTION INVOCATION
11. It must be noted that there is absolutely
no relation between names in different
namespaces. Two different modules may
both define same function without any
confusion because the functions are prefixed
with the module name. That means
module1.cmp() has no relation with
module2.cmp().
3. LOCAL NAMES IN A FUNCTION INVOCATION
13. A scope is a region of a Python program
where a namespace is directly accessible. The
location where the names are assigned in the
code determines the scope of visibility of the
name in that code.
SCOPE RULES
15. According to this rule, when a name is
encountered during the execution of the
program, it searches for that name in the
following order:
L. Local
E. Enclosing functions
G. Global (module)
B. Built-in (Python)
LEGB RULE
16. L. Local - It first makes a local search i.e. in
current def statement. The import
statements and function definitions bind
the module or function name in the local
scope. In fact, all operations that introduce
new names use the local scope.
LEGB RULE – L Local
17. E. Enclosing functions - It searches in all
enclosing functions, form inner to outer.
LEGB RULE – E. Enclosing functions
18. G. Global (module) - It searches for global
modules or for names declared global in a
def within the file.
LEGB RULE – G. Global (module)
19. B. Built-in (Python) - Finally it checks for any
built in functions in Python.
LEGB RULE – B. Built-in (Python)
21. Python is an object-oriented programming
language.
Object-oriented programming (OOP)
focuses on creating reusable patterns of
code.
A blueprint or prototypes created by a
programmer for an object is called class.
Class is a container of attributes and
methods. Its an Abstract Data Type (ADT)
Contd…
WHAT IS CLASS?
22. A USER-DEFINED PROTOTYPE for an
object that defines a set of attributes that
characterize any object of the class. The
attributes are data members (class variables
and instance variables) and methods,
accessed via dot notation.
Contd..
WHAT IS CLASS?
23. One of the principles of software
development is the DRY principle, which
stands for DON’T REPEAT YOURSELF. This
principle is geared towards limiting
repetition within code, and object-oriented
programming adheres to the DRY principle
as it reduces redundancy.
DRY PRINCIPLE
24. WHAT IS AN OBJECT?
Object is simply a collection of data
(variables) and methods (functions) that act
on those data.
OR
A unique instance of a data structure
that's defined by its class. An object
comprises both data members (class
variables and instance variables) and
methods.
Contd…
25. WHAT IS AN OBJECT?
OR
An instance of a class. This is the
realized version of the class, where the class
is manifested in the program.
NOTE:
In python everything is an object.
27. A Python class starts with the reserved
word 'class', followed by the class name and
a colon(:). The simplest form of class
definition looks like this:
class Test:
var=50
marks=10
def display(self):
print (self.var,self.marks)
DEFINING CLASS
29. DEFINING AN OBJECT AND FUNCTION CALL
After the class creation one can create
an object. The syntax is,
objectname=classname()
t1=Test()
t1.display()
OBJECT DEFINING
Calling member
function using object
30. CLASS VARIABLES or ATTRIBUTES or
DATA MEMBERS
A variable that is shared by all instances
of a class. Class variables are defined within a
class and are called ATTRIBUTES in python. In
other languages it is called as DATA MEMBER.
31. METHODS OR MEMBER FUNCTIONS
A Python method is like a Python function,
but it must be called on an object. And to create
it, you must put it inside a class
In other languages it is called as MEMBER
FUNCTION
Contd..
Python method is like a function, except it is
attached to an object. OR
An function defined in a class is called a
"method". Methods have access to all the data
contained on the instance of the object
32. METHODS OR MEMBER FUNCTIONS
METHOD DEFINING
Python method is a label that you can call
on an object; it is a piece of code to
execute on that object.
Contd..
34. self PARAMETER
self represents the instance of the class.
By using the "self" keyword we can access the
attributes and methods of the class in python.
NOTE:
self is not keyword. You can
use it as an identifier.
35. There is not strict rule that you have to
use self. It is the convention, one can use any
thing for example
Instead of
self me is used.
One can use
thisob or any
name.
YOU CAN USE ANYTHING INSTEAD OF self
36. DIFFERENCE BETWEEN METHODS AND
FUNCTIONS
There is a thin line between the functions
and the methods
The only major difference is that we
call Python method on an object, but it’s not
the same with functions. Also, methods may
modify an object; Python functions don’t.
38. pass STATEMENT
class Test:
pass
Python pass statement is used when a
statement is required syntactically but you
do not want any command or code to
execute. The pass statement is a null
operation; nothing happens when it
executes. For example:
41. del ATTRIBUTE
The del() method is used to delete the
named attribute from the object, with the
prior permission of the object.
Syntax is
del objectname, attributename
For example
del ob1,name
Contd… in next slide
45. SCOPE OF VARIABLES IN CLASS
Scope mean measure of access. It is the life
time of the variable.
In the class the scope of variable is
classified into 3 categories
1. Public
2. Private
3. Protected
46. SCOPE OF VARIABLES IN CLASS
1. Public
By default in class all attributes and
methods are public.
Public members (generally methods
declared in a class) are accessible from
outside the class. The object of the same
class is required to invoke a public method.
The public members are accessed with
dot (.) operator
47. 1. Public
Name and salary
are the attributes
by default public
Object also
accessing the
attribute salary
48. 2. Private
By declaring your data member
private you mean, that nobody should be
able to access it from outside the class, i.e.
strong you can’t touch this policy. Python
supports a technique called name mangling.
Salary is private
member not
accessible by
object or outside
49. 2. Private
Salary is private member
not accessible by object
or outside so attribute
error
50. 2. Private
Python performs name mangling of
private variables. Every member with double
underscore will be changed to
_object._class__variable. If so required, it
can still be accessed from outside the class,
but the practice should be refrained. (Refrain
means stop oneself from doing something)
For example:
Contd..
52. 2. Private
Output now private member
made accessible, though it is
private variable of class
53. 3. Protected
Protected member is (in C++ and Java)
accessible only from within the class and it’s
subclasses.
How to accomplish this in Python?
The answer is – by convention. By prefixing the
name of your member with a single underscore.
For Example:
Contd..
58. (c) Write a class PICTURE in Python with following
specifications : 4
Instance Attributes
– Pno # Numeric value
– Category # String value
– Location # Exhibition Location with
# String value
Methods :
– FixLocation() # A method to assign
# Exhibition Location as per
#Category
# as shown in the following table
CBSE QUESTION PAPER - 2015 DELHI
59. – Enter() # A function to allow user to
enter values
# Pno, Category and call
FixLocation() method
– SeeAll() # A function to display all the
data members
Category Location
Classic Amina
Modern Jim Plaq
Antique Ustad Khan
CBSE QUESTION PAPER - 2015 DELHI
61. (c) Write a class PHOTO in Python with following
specifications : 4
Instance Attributes
– Pno # Numeric value
– Category # String Value
– Exhibit # Exhibition Gallery with String value
Methods:
– FixExhibit() #A method to assign
#Exhibition Gallery as per
#Category
#as shown in the following table
CBSE QUESTION PAPER - 2015 OUTSIDE DELHI
62. Category Exhibit
Antique Zaveri
Modern Johnsen
Classic Terenida
-Register() #A function to allow user to
enter values #Pno, Category
and call FixExhibit() method
– ViewAll() #A function to display all the
data members
CBSE QUESTION PAPER - 2015 OUTSIDE DELHI
64. CBSE QUESTION PAPER - 2016 DELHI
(c) Write a class CITY in Python with following
specifications : 4
Instance Attributes
– Code # Numeric value
– Name # String value
– Pop # Numeric value for Population
– KM # Numeric value
– Density # Numeric value for Population
Density than 12000.
65. CBSE QUESTION PAPER - 2016 DELHI
Methods:
– CalDen() # Method to calculate Density
as Pop/KM
– Record() # Method to allow user to
enter values Code, Name, Pop,
KM and call CalDen() method
– See() # Method to display all the
data members also display a
message “Highly Populated
Area” if the Density is more
than 12000.
66. CLASS TEST
1. Write a program to illustrate class.
2.What is object? How it is created explain in
detail with suitable examples.
3.What is visibility mode? What are its types?
Explain in detail the various types of visibility
modes.
4. Explain in detail LEGB Rule
Class : XII Time: 40 Min
Topic: Classes & Objects Max Marks: 40
Each Question carries 5 Marks