>>> # There are four basic types of variables in Python >>> # - strings (illustrated in 1_basictypes_strings.py >>> # - integers (illustrated in 2_basictypes_numbers_booleans.py >>> # - floating point numbers (illustrated in 2_basictypes_numbers_booleans.py) >>> # - booleans (illustrated in 2_basictypes_numbers_booleans.py) >>> >>> # Basic Type #2: Integers >>> integer = 1 >>> print integer >>> >>> # converting an integer to a string of characters >>> integerString = str(integer) >>> print "integerString: " + integerString >>> >>> # converting a string to an integer >>> integer = int(integerString) >>> print integer >>> >>> # if you want to concatenate an integer with a another string you >>> # need to use the string representation of the integer >>> print "integer: " + str(integer) >>> >>> # Basic Type #3: Floating point numbers >>> # Floating point numbers are just decimal numbers (i.e., subdivisions of integers). >>> # The name 'floating point' is just related to how the numbers are stored within a computer >>> floatingPoint = 1.0 >>> print floatingPoint >>> >>> # converting a floating point number to a string >>> floatingPointString = str(floatingPoint) >>> print "floatingPointString: " + floatingPointString >>> >>> # converting a string to a floating point number >>> floatingPoint = float(floatingPointString) >>> >>> # Like before, if you want to concatenate the floating point number with a another string you >>> # need to use the string representation of the floating point number >>> print "floatingPoint: " + str(floatingPoint) >>> >>> # Basic Type #4: Booelean (i.e., True/False) values >>> booleanValue = True # (or False) >>> print booleanValue >>> >>> # converting a boolean value to a string >>> booleanString = str(booleanValue) >>> print "booleanString: " + booleanString >>> >>> # converting strings to boolean values >>> # (see http://docs.python.org/library/stdtypes.html for >>> # what is considered True vs. False for details) >>> booleanString = "True" >>> booleanValue = bool(booleanString) >>> print boleanValue >>> >>> # Like before, if you want to concatenate with another string you >>> # need to use the string representation of the boolean value >>> print "booleanValue: " + str(booleanValue) |