Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 20 Online
OpenStudy (anonymous):

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?

OpenStudy (anonymous):

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.

OpenStudy (anonymous):

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.

OpenStudy (anonymous):

http://docs.python.org/library/functions.html#type

OpenStudy (anonymous):

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..

OpenStudy (anonymous):

or isinstance(val, float)

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!