In Lecture 7's Handout, there is a line as such: type(val) == type(1.0) what does type(1.0) means? Does it means float by default or do I need to define it somewhere? how bout other types like integers and strings, do they have numbers as well?
That line is asking if val is a float. the function type(val) returns the type of val. So type(1.0) returns float, type (1) would return int, etc.
As something I always wondered, why is that doing something like type(val) == type(1.0), rather than type(val) == float is considered to be the idiomatic way? I always found the second a lot clearer.
ooo.. i got it.. so type(1.0) is simply the type of expression '1.0' which is a float? so I can use type(2.0) or type(1.6) as well. i thought type(1.0) was something specific..
or isinstance(val, float)
Join our real-time social learning platform and learn together with your friends!