CSC148H1 Lecture Notes - Lecture 4: Init, Docstring, Memory Address

59 views4 pages
School
Course
Professor
katrinasavvy and 38715 others unlocked
CSC148H1 Full Course Notes
1
CSC148H1 Full Course Notes
Verified Note
1 document

Document Summary

References: all code seen in the pictures can be found on the csc148 website: http://www. teach. cs. toronto. edu/~csc148h/winter/ Although python has a built-in type for floating-point numbers, there is no built-in type for representing rational numbers. Want to design and implement a class for rational numbers. Rational numbers are ratios of two integers p/q, where p is called the numerator and q is called the denominator. Operations on rational numbers include addition, multiplication and comparisons (>, If name is more than 1 word, use camel form. __init_: need to write to initialize classes or it will be inconvenient (as seen in the wrong way to write classes, most essential. __str_: useful for debugging code, to print code and see what it outputs vs. what"s expected. __eq_: next most essential, used to tell if 2 objects are equal. If you don"t write an __eq__ method, using the == will check the memory address instead. __lt_: special method, called every time you use < operator.

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