0
What is the class??and is every class must contain functions ..(def)
4 Réponses
+ 3
With classes, you define data and methods that work on that data. Functions are independent of that close bond with data. Types of processing that functions make more sense than classes would be calculating a minimum number of a set of arguments, displaying a pattern for a challenge, or averaging a set of arguments. You should use classes for things you have multiply versions of like, students taking a course, courses taught at a school, or people who work for the school.
+ 2
In Python, you must have a constructor def to store the class data on creation, but there isn't a need for others. Classes is a convenient way to group related data together.
Say you wish to draw triangles, rectangles, lines, and points on the display device. You could create a Point class with x & y coordinates, a Line class with a start & end points, a Triangle class with 3 lines, and a Rectangle class with 4 lines.
+ 1
Class is the type of object that stores the set of somehow connected attributes and methods that you wish to use more then once (creating instances).
Strictly saying, you need NOT to define anyting iside the class declaration:
>>> class A():
pass
This is a valid class declaration, though it is a little bit useless since you'd have to define methods afterwards if you want your class to have any use.
0
but what is the different between calsses and functions?