# types.py # # Try the following and see what you get. The function 'type' given an # argument, say 3, returns the type of the value 3 which is an integer. # The integer type is represented as in Python. type (3) # Now, real numbers (aka floating point numbers): type (3.14) # And two boolean values type (True) type (False) # And strings this time type ("3") type ("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 another. That way, it would # not try to do things that would not make sense, for example, trying to # add a number to a string. It also uses the type information to decide # how much memory to use to represent a value in memory. An integer is # typically represented using a smaller amount of memory (say 32 bits) # than the amount of memory used to represent a real number (say 64 bits). # So, type information for any value we use in a program is important for # the language processor as well as for the programmers who write # application programs. # In this tutorial we will deal with only a small number of types which # will still be sufficient for the kinds of programs that we will write.