Python基础学习代码之变量和类型
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python基础学习代码之变量和类型相关的知识,希望对你有一定的参考价值。
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 e def func1(x): return x + x x = [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 os while 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 == ‘.‘: 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: 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!‘ continue
本文出自 “xwb” 博客,请务必保留此出处http://xiewb.blog.51cto.com/11091636/1792265
以上是关于Python基础学习代码之变量和类型的主要内容,如果未能解决你的问题,请参考以下文章