# exp3.py3 example file more complete structure, list, arrays, matrix import math from numpy import array # for vector and matrix def main(): print("exp3.py3 running") a_list=[7, 7.25, "abc"] # any types print("a_list=",a_list) print("a_list[2]=",a_list[2]) # selecting item 2, start with 0 a_list.append("def") # append to end of list print("append=",a_list) del a_list[1] # delete a selected item print("delete=",a_list) print("len(a_list)=",len(a_list)) # get the length of a list print(" ") a_tuple=2, 3, 5, 7 # can not modify all same type b_tuple=(2, 3, 5, 7) # same data as above all same type print("a_tuple=",a_tuple) print("b_tuple=",b_tuple) print("b_tuple[2]=",b_tuple[2]) # select item 2 for printing # b_tuple[2] = 9 # no modify selected item print(" ") dict={1:'a', 2:'b', 3:'c'} # dictionary key : value print("dict=",dict) dict[5]='e' print("dict[5]=e",dict) print("dict[3]=",dict[3]) # look up by key print(" ") z=range(5) # zero based, length 5, no 5 print("range(5)=",z) z=range(1,5) # 1 based, length 4, no 5 print("range(1,5)=",z) z=range(1,7,2) # step size 2, no 7 print("range(1,7,2)=",z) print(" ") Y = array([0.0 for i in range(4)]) # initialize to zero print("array([0.0 for i in range(4)])=") print(Y) A = array([[1.0 for j in range(4)] for i in range(3)]) # initialize to 1 print("array([1.0 for j in range(4)] for i in range(3)])=") print(A) A[2,3] = 2.0 print("A[2,3] = 2.0") print(A) print(" ") if __name__ == '__main__': main()