Listing 1 def palindrome?selfself.reverse end # example call: \"refer\".palíndro
ID: 3735140 • Letter: L
Question
Listing 1 def palindrome?selfself.reverse end # example call: "refer".palíndrome ? #=> true 5. (3 pts) Which of the following statements is TRUE regarding Listing 1, checking if a string reads the same backwards as forwards? A. You could add this method to the String class by reopening String and defining palindrome? s a class B. C. The method will work correctly when added to any class that provides a class method reverse. method there. You could add this as a class method in the String class by putting it in a module, reopening String, and using include to "mix" that module into String. D. The method will work correctly when mixed into any class whose instances respond to reverse by returning a reversed version of themselves. The method will work correctly if the class includes theExplanation / Answer
answer-> D.
beacause we cannot override or change any built-in class in python as those are coded in C.What you can do is subclass the type. Here is an example :
Test:
You could also overwrite the str-type with class str(str):, but that doesn't mean you can use the literal "test", because it is linking to the builtin str.
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.