<< Main Manual

Tutorial #0.2. Basic Variable Types -- Numbers and Booleans

TIP #1: The following examples are a crash course in Python programming showing the features that are most beneficial with the minimal amount of extraneous information. You can type the example code directly within PhysImage's 'Jython Console' or load the example files (*.py links below) directly from PhysImage as a demonstration, or test the code out with an independent installation of Python 2.7 on your preferred OS platform. These examples are independent of any specific PhysImage features and meant to be a succinct demonstration of very useful general Pythonic features.

TIP #2: The ">>> ", in the below example, is meant to represent PhysImage's 'Jython Console' prompt, while '#' in a line represents a comment (used to annotate Python code) and does not do anything. Therefore,
the text following the '#' is only for your benefit to understand the next bits of code and is not required to be typed in.

For a more expansive tutorial of the general Python programming language, see the Official Python Tutorial.

Example

The following code can be loaded within PhysImage from this file or typed in manually.

>>> # 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
)

After the data is in the WaveManager it got manipulated or plotted as a chart in the previously demonstrated ways.

<< Tutorial #0.1. Basic Variables Types -- Strings
>> Tutorial #0.3. Lists and Dictionaries

<< Main Manual