# types.py # # See what the following prints to the standard ouput (the computer # screen). The function type given an argument 3 returns the type of # the value 3 which is an integer which is represented with a short # hand notation print type (3) # Similarly here is a floating point number given to find its type in python. print type (3.14) # And two boolean values print type (True) print type (False) # And strings this time print type ("3") print type ("It is a nice day outside.") # This is intetesting. The python interpreter will read this line and # and recognizes it as a string value, but that is all it will do since # the interpreter was not asked to do anything beyond that. Compare this # with the next one that follows this. There, it is asked to print the # recognized value, which is the string value and indeed it will be printed # on the standard output device, i.e., the screen. "It is a nice day outside." # This will not only recognize it but also prints the value to the screen. print "It is a nice day outside." # As you may have recognized it by now, any value the language Python, or # any programming language in general, deals with has a type associated # with the value. By using the type information a language processor # (interpreter in the case of Python) understands what it is dealing with # and distinguishes one type of value from other types. That way, it would # not try to do things that would not make sense for example, adding a number # to a string.