# hello.py example file indetation and blank lines important # simple .py can be without def main(): # if __name__ == '__main__': # main() import math def main(): print "hello from python" # three ways to print the same line print 'hello from python' print "hello", print "from python" a_int=7 a_float=7.25 a_real=7.2597256357e+300 print "a_int=", print a_int print "a_float=", print a_float print "a_real=", print a_real a_list=[7, 7.25, "abc"] print "a_list=", print a_list print "a_list[2]=", print a_list[2] a_list.append("def") print "append=", print a_list del a_list[1] print "delete=", print a_list print "len(a_list)=", print len(a_list) print " " a_tuple=2, 3, 5, 7 # can not modify b_tuple=(2, 3, 5, 7) # same as above print "a_tuple=", print a_tuple print "b_tuple=", print b_tuple print "b_tuple[2]=", print b_tuple[2] print " " dict={1:'a', 2:'b', 3:'c'} # dictionary key : value print "dict=", print dict dict[5]='e' print "dict 5=", print dict print "dict[3]=", # look up by key print dict[3] print " " z=range(5) print "range(5)=", print z z=range(1,5) print "range(1,5)=", print z z=range(1,7,2) print "range(1,7,2)=", print z x = 0.7071 print "x = ", print x print "anyfunct(x) = note complex result", print anyfunct(x) # end of main def anyfunct(x): # thus main can be in front of needed funstions, cmath also z = math.cos(x) + 1.0j*math.sin(x) - math.sqrt(x) return z if __name__ == '__main__': main() # end of hello/py see also test_math.py