LS26 - Operator Overloading

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

Suppose you had a class named Fraction representing fractions like 1/2 or 3/4. Further suppose you have two Fraction objects named a and b. If you wrote the expression a + b, Python would look in your class and choose the first method whose first parameter is self and second parameter is of type Fraction.

F

You are encouraged to define as many overloads for classes you design as possible, even when it is a bit of a stretch of the imagination as to how a given operator relates to the logic you decided to use for it. The conciseness of operator overloading is always worthwhile.

F

Even though objects don't have the ability to use subscription notation inherently, you can overload the subscription operator by implementing the special __getitem__ method.

T

In Python, when you design a class you are able to define what it means when objects of your class are multiplied, added, and so on to other values.

T

Popular libraries will often make responsible use of operator overloading.

T

The Point class shown in the video for Operator Overloading has a __repr__ method that, based on the contents of the previous video, more correctly should have been named __str__.

T


Ensembles d'études connexes

Unit 3: World War I Review Sheet - CASSIDY

View Set

Lesson 1: Observing the Night Sky

View Set

Standard Form of Linear Equations, Standard Form of Linear Equations, Linear equation forms

View Set

Wa Life and Disability Insurance - Washington Laws and Rules

View Set

ECON 2143 Exam #2 Chapter 12 & 13 Study Questions

View Set

NSG 333 Ch 23- Nursing Care of the Newborn with Special Needs

View Set

Exam 1 Questions (CH. 1-3 LT & Quizzes)

View Set

SmartBook Chapter 10: Planning for Capital Investments

View Set