INFO1110 Lecture Notes - Lecture 2: Init, Order Of Merit, Harper Lee

15 views1 pages

Document Summary

We can think of classes as a template for all the variables and methods of a particular kind of object. Consider books as an example: all books have certain properties, or attributes. For example: title, author, year of publication, etc: if we de ne a template for the creation of such objects, we can easily keep track of all the data relating to that one speci c item. This also allows us to make multiple different instances of that class, i. e. making and storing data for lots of different books. A constructor tells you how to build an object. It creates a space in memory for the object when it is called. In python, we declare the constructor using __init__. self is a keyword to describe and refer to the instance of the class. class book: def __init__(self, title, author, year): self. title = title self. author = author self. year = year.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents