<< Main Manual

Tutorial #0.1. Basic Variable Types -- Strings

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 example below is meant to represent PhysImage's 'Jython Console' prompt, "... " indicates the continuation of a multi-line (or block) statement 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 you and any other reader's benefit to understand the next bits of code and is not required to be typed in or even executed.

For a more expansive tutorial of the general Python programming language, see the Official Python Tutorial, but we believe the following few lessons are most succinct for many people's purposes.

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 #1: Strings of text characters (i.e., the data type referred to as 'string[s]')
>>> stringValue1 = "some text"
>>>
>>> # printing a string to the console
>>> print stringValue1
>>>
>>> # concatenating strings
>>> stringValue2 = stringValue1 + " and some more text"
>>> print stringValue2
>>>
>>> stringValue3 = '''string value that
... can extend to additional lines'''
>>> print stringValue3
>>>
>>> # new line characters (\n)
>>> stringValue4 = stringValue2 + " with an extra line\nat the end"
>>> print "stringValue4: " + stringValue4
>>>
>>> # tab characters (\t)
>>> stringValue5 = stringValue4 + "\t" + "and with indented text"
>>> print "stringValue5: " + stringValue5


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

<< Main Manual