SlideShare uma empresa Scribd logo
1 de 71
Module 3
LISTS, DICTIONARIES ,TUPLES and
REGULAR EXPRESSIONS
Lists
• A list is a sequence
Like a string, a list is a sequence of values. In a
string, the values are characters; in a list, they
can be any type. The values in list are called
elements or sometimes items.
A list that contains no elements is called an empty list;
you can create one with empty brackets, [ ].
Lists are mutable
• The syntax for accessing the elements of a list
is the same as for accessing the characters of a
string: the bracket operator.
• Any integer expression can be used as an
index.
• If you try to read or write an element that
does not exist, you get an IndexError.
• If an index has a negative value, it counts
backward from the end of the list.
Traversing a list
• The most common way to traverse the
elements of a list is with a for loop.
• if you want to write or update the elements,
you need the indices. A common way to do
that is to combine the functions range and
len:
List slices
List methods
• pop modifies the list and returns the element
that was removed. If you don’t provide an
index, it deletes and returns the last element.
• The sum() function only works when the list elements are
numbers. The other functions (max(), len(), etc.) work with
lists of strings and other types that can be comparable.
Dictionaries
• Dictionary as a set of counters
Suppose you are given a string and you want to
count how many times each letter appears.
There are several ways you could do it:
• 1. You could create 26 variables, one for each
letter of the alphabet. Then you could traverse
the string and, for each character, increment
the corresponding counter, probably using a
chained conditional.
• 2. You could create a list with 26 elements.
Then you could convert each character to a
number (using the built-in function ord), use
the number as an index into the list, and
increment the appropriate counter.
• 3. You could create a dictionary with
characters as keys and counters as the
corresponding values. The first time you see a
character, you would add an item to the
dictionary. After that you would increment the
value of an existing item.
Tuples
• Tuples are immutable
Module 4
• Classes and Objects
• Classes and Functions
• Classes and methods
Classes and Objects
CLASSES AND OBJECTS
• Python is an object-oriented programming language,
and class is a basis for any object oriented
programming language.
• Class is a user-defined data type which binds data and
functions together into single entity.
• Class is just a prototype (or a logical entity/blue print)
which will not consume any memory.
• An object is an instance of a class and it has physical
existence.
• One can create any number of objects for a class.
• A class can have a set of variables (also known as
attributes, member variables) and member functions
(also known as methods).
Programmer-Defined Types
• A class in Python can be created using a
keyword class.
• creating an empty class without any members
by just using the keyword pass within it.
class Point:
pass
print(Point)
• The process of creating a new object is called
as instantiation and the object is instance of a
class.
Attributes
• class attributes are class variables that are
inherited by every object of a class.
• One can assign values to these attributes using dot
operator.
• For example, keeping coordinate points in mind,
we can assign two attributes x and y for the object
of a class Point as below
p.x =10.0
p.y =20.0
x= p.x
>>> print(x)
10.0
Rectangles
Instances as return values
• Functions can return instances. For example,
find_center takes a Rectangle as an argument
and returns a Point that contains the coordinates
of the center of the Rectangle:
• Write a class Point representing a point on
coordinate system. Implement following
functions
o A function read_point( ) to receive x and y
attributes of a Point object as user input.
o A function distance() which takes two objects of
Point class as arguments and computes the
Euclidean distance between them.
o A function print_point()to display one point in
the form of ordered-pair.
Copying
• Copying an object is often an alternative to
aliasing. The copy module contains a function
called copy that can duplicate any object.
class Point:
pass
p1=Point()
p1.x=10
p1.y=20
p2=p1
>>> print(p1)
< main .Point object at 0x01581BF0>
>>> print(p2)
< main .Point object at 0x01581BF0>
Classes and Functions
• Time
programmer-defined type, we’ll define a class called Time that
records the time of day. The class definition looks like this:
Pure functions
Modifiers
Prototyping versus planning
Whenever we do not know the complete problem statement, we may
write the program initially, and then keep of modifying it as and when
requirement (problem definition) changes. This methodology is known
as prototype and patch.
first design the prototype based on the information available and
then perform patch-work as and when extra information is gathered.
But, this type of incremental development may end-up in
unnecessary code, with many special cases and it may be unreliable
too.
What is prototype and patch?
prototype and patch: A development plan that involves writing a rough draft of a
program, testing, and correcting errors as they are found.
Classes and Methods
Object-Oriented Features
• Programs include class and method
definitions.
• Most of the computation is expressed in terms
of operations on objects.
• Objects often represent things in the real
world, and methods often correspond to the
ways things in the real world interact.
function which is associated with a particular class is known
as a method.
Methods are semantically the same as functions, but there are two
syntactic differences:
Methods are defined inside a class definition in order to make the
relationship between the class and the method explicit.
The syntax for invoking a method is different from the syntax for
calling a function.
Pointing Objects
The init () Method
class Point:
def __init__ (self,x=0,y=0):
self.x=x
self.y=y
P1=Point()
_ _str_ _ method
• It’s a special method it is used to return a
string representation of an object.

Mais conteúdo relacionado

Semelhante a Module 3,4.pptx

Python programming
Python programmingPython programming
Python programmingsirikeshava
 
Python Programming - VI. Classes and Objects
Python Programming - VI. Classes and ObjectsPython Programming - VI. Classes and Objects
Python Programming - VI. Classes and ObjectsRanel Padon
 
Concept of Object-Oriented in C++
Concept of Object-Oriented in C++Concept of Object-Oriented in C++
Concept of Object-Oriented in C++Abdullah Jan
 
Lec01-Algorithems - Introduction and Overview.pdf
Lec01-Algorithems - Introduction and Overview.pdfLec01-Algorithems - Introduction and Overview.pdf
Lec01-Algorithems - Introduction and Overview.pdfMAJDABDALLAH3
 
Python for katana
Python for katanaPython for katana
Python for katanakedar nath
 
C++ training
C++ training C++ training
C++ training PL Sharma
 
Summer Training Project On Python Programming
Summer Training Project On Python ProgrammingSummer Training Project On Python Programming
Summer Training Project On Python ProgrammingKAUSHAL KUMAR JHA
 
2. Values and Data types in Python.pptx
2. Values and Data types in Python.pptx2. Values and Data types in Python.pptx
2. Values and Data types in Python.pptxdeivanayagamramachan
 
Python For Data Science.pptx
Python For Data Science.pptxPython For Data Science.pptx
Python For Data Science.pptxrohithprabhas1
 
Q-Step_WS_06112019_Data_Analysis_and_visualisation_with_Python.pptx
Q-Step_WS_06112019_Data_Analysis_and_visualisation_with_Python.pptxQ-Step_WS_06112019_Data_Analysis_and_visualisation_with_Python.pptx
Q-Step_WS_06112019_Data_Analysis_and_visualisation_with_Python.pptxkalai75
 
Learn advanced java programming
Learn advanced java programmingLearn advanced java programming
Learn advanced java programmingTOPS Technologies
 

Semelhante a Module 3,4.pptx (20)

Pa2 session 1
Pa2 session 1Pa2 session 1
Pa2 session 1
 
Pa1 session 2
Pa1 session 2 Pa1 session 2
Pa1 session 2
 
Python-Basics.pptx
Python-Basics.pptxPython-Basics.pptx
Python-Basics.pptx
 
Module 4.pptx
Module 4.pptxModule 4.pptx
Module 4.pptx
 
Java
JavaJava
Java
 
O6u CS-315A OOP Lecture (1).pdf
O6u CS-315A OOP Lecture (1).pdfO6u CS-315A OOP Lecture (1).pdf
O6u CS-315A OOP Lecture (1).pdf
 
Python programming
Python programmingPython programming
Python programming
 
Python Programming - VI. Classes and Objects
Python Programming - VI. Classes and ObjectsPython Programming - VI. Classes and Objects
Python Programming - VI. Classes and Objects
 
Concept of Object-Oriented in C++
Concept of Object-Oriented in C++Concept of Object-Oriented in C++
Concept of Object-Oriented in C++
 
Lec01-Algorithems - Introduction and Overview.pdf
Lec01-Algorithems - Introduction and Overview.pdfLec01-Algorithems - Introduction and Overview.pdf
Lec01-Algorithems - Introduction and Overview.pdf
 
Python for katana
Python for katanaPython for katana
Python for katana
 
C++ training
C++ training C++ training
C++ training
 
Summer Training Project On Python Programming
Summer Training Project On Python ProgrammingSummer Training Project On Python Programming
Summer Training Project On Python Programming
 
2. Values and Data types in Python.pptx
2. Values and Data types in Python.pptx2. Values and Data types in Python.pptx
2. Values and Data types in Python.pptx
 
Python For Data Science.pptx
Python For Data Science.pptxPython For Data Science.pptx
Python For Data Science.pptx
 
Python Basics.pptx
Python Basics.pptxPython Basics.pptx
Python Basics.pptx
 
Python-Classes.pptx
Python-Classes.pptxPython-Classes.pptx
Python-Classes.pptx
 
Q-Step_WS_06112019_Data_Analysis_and_visualisation_with_Python.pptx
Q-Step_WS_06112019_Data_Analysis_and_visualisation_with_Python.pptxQ-Step_WS_06112019_Data_Analysis_and_visualisation_with_Python.pptx
Q-Step_WS_06112019_Data_Analysis_and_visualisation_with_Python.pptx
 
Python with data Sciences
Python with data SciencesPython with data Sciences
Python with data Sciences
 
Learn advanced java programming
Learn advanced java programmingLearn advanced java programming
Learn advanced java programming
 

Último

Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapRishantSharmaFr
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXssuser89054b
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityMorshed Ahmed Rahath
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxJuliansyahHarahap1
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoordharasingh5698
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptxJIT KUMAR GUPTA
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptNANDHAKUMARA10
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationBhangaleSonal
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Standamitlee9823
 

Último (20)

(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
(INDIRA) Call Girl Meerut Call Now 8617697112 Meerut Escorts 24x7
 
Unleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leapUnleashing the Power of the SORA AI lastest leap
Unleashing the Power of the SORA AI lastest leap
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Palanpur 7001035870 Whatsapp Number, 24/07 Booking
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoorTop Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
Top Rated Call Girls In chittoor 📱 {7001035870} VIP Escorts chittoor
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bangalore ☎ 7737669865 🥵 Book Your One night Stand
 

Module 3,4.pptx

  • 1. Module 3 LISTS, DICTIONARIES ,TUPLES and REGULAR EXPRESSIONS
  • 2. Lists • A list is a sequence Like a string, a list is a sequence of values. In a string, the values are characters; in a list, they can be any type. The values in list are called elements or sometimes items.
  • 3. A list that contains no elements is called an empty list; you can create one with empty brackets, [ ].
  • 4. Lists are mutable • The syntax for accessing the elements of a list is the same as for accessing the characters of a string: the bracket operator.
  • 5. • Any integer expression can be used as an index. • If you try to read or write an element that does not exist, you get an IndexError. • If an index has a negative value, it counts backward from the end of the list.
  • 6.
  • 7. Traversing a list • The most common way to traverse the elements of a list is with a for loop. • if you want to write or update the elements, you need the indices. A common way to do that is to combine the functions range and len:
  • 8.
  • 9.
  • 10.
  • 13.
  • 14. • pop modifies the list and returns the element that was removed. If you don’t provide an index, it deletes and returns the last element.
  • 15.
  • 16. • The sum() function only works when the list elements are numbers. The other functions (max(), len(), etc.) work with lists of strings and other types that can be comparable.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 30.
  • 31.
  • 32.
  • 33. • Dictionary as a set of counters Suppose you are given a string and you want to count how many times each letter appears. There are several ways you could do it:
  • 34. • 1. You could create 26 variables, one for each letter of the alphabet. Then you could traverse the string and, for each character, increment the corresponding counter, probably using a chained conditional. • 2. You could create a list with 26 elements. Then you could convert each character to a number (using the built-in function ord), use the number as an index into the list, and increment the appropriate counter.
  • 35. • 3. You could create a dictionary with characters as keys and counters as the corresponding values. The first time you see a character, you would add an item to the dictionary. After that you would increment the value of an existing item.
  • 36.
  • 38. Module 4 • Classes and Objects • Classes and Functions • Classes and methods
  • 39. Classes and Objects CLASSES AND OBJECTS • Python is an object-oriented programming language, and class is a basis for any object oriented programming language. • Class is a user-defined data type which binds data and functions together into single entity. • Class is just a prototype (or a logical entity/blue print) which will not consume any memory. • An object is an instance of a class and it has physical existence. • One can create any number of objects for a class. • A class can have a set of variables (also known as attributes, member variables) and member functions (also known as methods).
  • 40. Programmer-Defined Types • A class in Python can be created using a keyword class. • creating an empty class without any members by just using the keyword pass within it. class Point: pass print(Point)
  • 41.
  • 42. • The process of creating a new object is called as instantiation and the object is instance of a class.
  • 43.
  • 44. Attributes • class attributes are class variables that are inherited by every object of a class. • One can assign values to these attributes using dot operator. • For example, keeping coordinate points in mind, we can assign two attributes x and y for the object of a class Point as below p.x =10.0 p.y =20.0
  • 45.
  • 47.
  • 48. Instances as return values • Functions can return instances. For example, find_center takes a Rectangle as an argument and returns a Point that contains the coordinates of the center of the Rectangle:
  • 49. • Write a class Point representing a point on coordinate system. Implement following functions o A function read_point( ) to receive x and y attributes of a Point object as user input. o A function distance() which takes two objects of Point class as arguments and computes the Euclidean distance between them. o A function print_point()to display one point in the form of ordered-pair.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54. Copying • Copying an object is often an alternative to aliasing. The copy module contains a function called copy that can duplicate any object. class Point: pass p1=Point() p1.x=10 p1.y=20 p2=p1 >>> print(p1) < main .Point object at 0x01581BF0> >>> print(p2) < main .Point object at 0x01581BF0>
  • 55.
  • 56.
  • 57. Classes and Functions • Time programmer-defined type, we’ll define a class called Time that records the time of day. The class definition looks like this:
  • 58.
  • 61. Prototyping versus planning Whenever we do not know the complete problem statement, we may write the program initially, and then keep of modifying it as and when requirement (problem definition) changes. This methodology is known as prototype and patch. first design the prototype based on the information available and then perform patch-work as and when extra information is gathered. But, this type of incremental development may end-up in unnecessary code, with many special cases and it may be unreliable too. What is prototype and patch? prototype and patch: A development plan that involves writing a rough draft of a program, testing, and correcting errors as they are found.
  • 62.
  • 63. Classes and Methods Object-Oriented Features • Programs include class and method definitions. • Most of the computation is expressed in terms of operations on objects. • Objects often represent things in the real world, and methods often correspond to the ways things in the real world interact.
  • 64. function which is associated with a particular class is known as a method. Methods are semantically the same as functions, but there are two syntactic differences: Methods are defined inside a class definition in order to make the relationship between the class and the method explicit. The syntax for invoking a method is different from the syntax for calling a function.
  • 66.
  • 67.
  • 68. The init () Method
  • 69.
  • 70. class Point: def __init__ (self,x=0,y=0): self.x=x self.y=y P1=Point()
  • 71. _ _str_ _ method • It’s a special method it is used to return a string representation of an object.