课程: Programming Concepts for Python
免费学习该课程!
今天就开通帐号,24,700 门业界名师课程任您挑!
Classes
- Out of the box, object-oriented programming languages give us the ability to create objects for common types of things like representing numbers and strings. But if I want to create my own custom types of objects, I can do so by defining classes, which are the blueprints used to create new objects. A class defines the attributes and methods that make up a specific type of object. This class for a pair of blue jeans will describe its attributes for waist size, length, and color, as well as methods for donning and removing the jeans. This blueprint might also have a special constructor method for creating a new pair of jeans object, which allows me to specify values for size, length, and color when I create a new jeans object. If I wanted to construct a new pair of jeans, I could do so by following these blueprints to give the new object the appropriate attributes. But I'm not that good at sewing. As a modern man, I buy…