Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
self.value and self?
How come we dont use self.value + other ? Why we use self + other instead ?
Steven Parker210,424 Points
By using "self", the appropriate conversion method (either "
__int__" or "
__float_") will be invoked automatically to return the value in the correct format for what it is being combined with.
I still don't understand why he's using self instead of self.value? Could you please explain it with examples?
Jamaru Rodgers3,046 Points
Hi Steven Parker,
So you're saying that when using "self.value", we're always going to be a string because we converted it to one with str right? And when we use "self" by itself, "self" automatically conforms to the data type we need it to be? There's no need to convert the type with it at all?
If this is the case:
- Why not just use "self" instead of "self.value" for everything?
- Couldn't we just keep converting "self.value" to the data type we needed in each situation?
I know using self by itself if probably more efficient as far as the py system goes, but wouldn't they both work? I was also confused as to why he used both ways all in the same class.