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.
How does 'other' instance know it will be treated as float?
In the magic method add(self, other), it returns float(self) + other (and int(self) + other ). How does 'other' instance know it is float? Don't we have to have float(self) + float(other)? I guess it automatically matches to the return type of self, but I know fully understand the mechanics of it.
Variables in Python follow the standard nomenclature of an alphanumeric name beginning in a letter or underscore. Variable names are case sensitive. Variables do not need to be declared and their datatypes are inferred from the assignment statement. So, Python use an aggressive type of inference. This means that python does not knows the type of variable until it runs the program, that's when it knows whether its int or float or string.