Python learning step by step

# # # # # My own Python learning file # # # # # % 1. Data types % 2. % 3. % 4. 1. mystring = "Hello World!" # string print mystring # Output: # Hello World! # strings can also be defined within single quotes 'Hello World!' myint = int(5) # integer number print myint # Output: 5 myfloat = float(5) # floating point number print myfloat print "Printing float(5) with 2 decimals as a string gives %.2f" % myfloat # Output: # 5.0 # Printing float(5) with 2 decimals as a string gives 5.00 # .2f specifies floating numbers with 2 digits to the right of the decimal # other argument specifiers # %s - string (or a number to be represented as a string) # %d - integer # %f - floating point number # %x - integers in hex representation (lowercase) # %X - integers in hex representation (uppercase) mylist = [2, 3, 5, 7] # list myodd = [1, 3, 5, 7] myeven = [2, 4, 6, 8] myall = mylist + myodd + myeven print myall # Output: # [2, 3, 5, 7, 1, 3, 5, 7, 2, 4, 6, 8] # a list is not a vector # to define custom vectors and matrices, see http://www.math.okstate.edu/~ullrich/PyPlug/ # for a shortcut, see http://www.scipy.org/NumPy_for_Matlab_Users # # # # # #