More information about the Python programming language can be found at the following location: http://www.python.org/doc/. A Python tutorial can be found at the following location: http://docs.python.org/2/tutorial/
None - This data type is the equivalent of Java's null.
boolean - This data type has one of two values. True or False. Alternatively you can use 1 or 0.
int - Signed integers, 32 bits in size.
long - Integers which can contain as many bits as required. They are differentiated by appending an L to the end of a number: 1245L as opposed to 1245
float - Floating point numbers, such as 23.84
Variables in Python are not defined like they are in Java. All variable types are determined implicitly. For instance:
myVar = 1 + 1
This line will declare a variable myVar which is an integer equal to the sum of 1 and 1. This applies for complex objects as well, such as:
data = SeismicData("C:\\data\\segy\\cdp_stack.xgy")
This will declare the variable data. The type will be determined by what is on the right hand side, which in this case is SeismicData.
Arrays are just as easy to declare as any other variable. To declare an array simply place your comma delimited values within square brackets.
myArray = [1, 2, 3, 4, 5]
The same works for arrays of objects:
myDataArray = [data1, data2, data3]
In instances where you need a typed array (ex: an array of ints), use this syntax:
import array as arr
myDataArray= arr.array('i')
To add items to an array, use the append method
myDataArray.append(3)
for num in range(2, 10):
print "Found a number:", num
Note that the loop above will start at 2 and stop after 9 (and not 10)
for num in range(2, 10, 2):
print "Found an even number:", num
fruits = ['banana', 'apple', 'mango']
for fruit in fruits:
print 'Found a fruit:', fruit
while True:
print "This can take a while"
Comments in python are written by using the # character. Ex:
#This is a comment taking up a full line
myVar = 10**2 # This line sets myVar equal to 10 squared.
A Frequently Asked Questions article is also available.