Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Which of the following is *not* a method of dir(float_a) where float_a = 1.2?

The possible answers were round, conjugate, as_integer_ratio and is_integer. All of which I think is correct, but maybe I'm wrong. Please clarify. This is one of the questions in the Python Quiz.

2 Answers

It asks you to try it in Workspaces, if you do that you will get a list of methods. Notice that some are "built in" methods and have __ name (with underscores) instead of just 'name'. That's basically what it's asking you to distinguish. Which one is the built in one and not directly a method of dir(float). Only one of them is a built in method.

I did, but now I understand. Round is the answer. Thanks.

What is the difference between a built in method and any other method?

I believe they're the ones that are built into the Python language/interpreter itself and so available across the language to use with any class. As opposed to methods only available on certain classes. Or methods you've created yourself.

Marko Koron
Marko Koron
20,658 Points

Since there are a lot of methods is hard to read the output so you can use the following trick dir(float_a.conjugate), dir(float_a.as_integer), ... You will see that one call wil give an error. In the end the correct answer was a method for which I was 100% sure that belonged to float :D.

I disagree as it wouldn't give you an error on the one that is built in compared to explicitly the float. I just tried now in the workspace and the correct answer and one of the incorrect answers gave identical results.

Marko Koron
Marko Koron
20,658 Points

Sorry, but are wrong on this one. :)

I tried float.round() and got an error "AttributeError: 'float' object has no attribute 'round' ", whereas, float.is_integer() return false, float.as_integer_ratio() return (5404319552844595, 4503599627370496) and float.conjugate() return 1.2.