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
self.value and self?
How come we dont use self.value + other ? Why we use self + other instead ?
Steven Parker228,978 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.