foo = ' abc ' For i in range (Len (foo)): print "%D  %s " % (I, foo[i]) Print [x ** 2 for x in range (5) If not x % 2]try: f = open (' e:\XIN_370_logic.tx ', ' r ') for eachline in f: Print eachline f.close () Except ioerror, e: print  EDEF FUNC1 (x): return x + xx = [i for i in range (4)]print func1 (x) Def func2 (debug=true): if debug: print ' true,in debug mode! ' print ' Done ' Func2 (False) "" "" "" A = int (Raw_input (' input num1: ')) b = int (Raw_input (' input num2: ')) C = int (Raw_input (' input num3: ')) alist = [a, b, c]minalist = Min (alist) Maxalist = max (alist) medalist = [x for x in alist if x != minalist and x!= maxalist]medalist = medalist[0]print Minalist, medalist, maxalist "" "import oswhile true: ar = Raw_input ("read or write file[r/w],enter . to quit>>") if ar == ' W ': ls = os.linesep globals (LS) While true: os.chdir (r "e:\\") filename = raw_input (' Input filename: ') if os.path.exists (filename): print ' file %s Already exists! ' % filename else: break all = [] print "\ Nenter lines ('. ') by is self to quit). \ n " while True: entry = raw_input (' > >> ') if entry == ' . ':               &NBsp; print ' Quit ' break else: all.append (Entry) f = open (filename, ' W ') print all for eachline in all: f.writelines ("%s%s" % (EACHLINE, LS) f.close () elif ar == ' R ': filename = raw_input (' Input filename: ') print try: &nbsP; os.chdir (r "e:\\") f = open (filename, ' R ') except IOError: print ' file %s is not exists! ' % filename else: for eachline in f: print eachline f.close () elif ar == '. ': break else: print ' input error,input again! ' &nbsP; continue
This article is from the "XWB" blog, make sure to keep this source http://xiewb.blog.51cto.com/11091636/1792265
Variables and types of Python-based learning code