반응형 프로그래밍 기초/Python15 [Python] 반복문 data1 = range(1,10) #1~9의 값을 가지는 리스트 생성data2 = 0 for i in data1: print i while data2 < 10: data2+=1 if data2 % 2: print data2, #홀수면 출력 else: continue #짝수면 아래 구문 무시하고 반복문 다시 진행 if data2 == 7: break #data2가 7이면 반복문을 빠져나옴 2016. 3. 2. [Python] 조건문 #조건문a=1b=2c=3d=4s="show me the money" x=[1,2]y=[1,2] if a < b: print "bbbb"elif b < a: print "aaaa"else: print "aabb" if a < b and b < c and not (d < c): print "dddd" if "money" in s: # 좌측 문자열이 우측 문자열 또는 객체에 포함되어있는지 확인 print "money in string" if x is y: #동일한 객체인지 비교 print "x and y is same object" if x == y: #객체의 값이 같은지 비교 print "x's value and y's value is same" if type(x) is type(y): #객체의 타입이 같은.. 2016. 3. 2. [Python] 입출력 (stdin, stdout) import sys i=0.5353s="text"t=sys.argv[0] #명령줄 인수를 읽어옴 print "Hello World %.2f %d" % (i,2016)# 파이썬 3에서는 print 다음에 ()가 들어감 ex: print("Hello World %.2f %d" % (i,2016)) print "file name is %s" % (t) print format(i,"10.2f"),format(s,"20s"),"123" #format 함수의 2번째 인자는 포맷지정자 sys.stdout.write("input : ")t=sys.stdin.readline() print t t= raw_input("input : ") # input("input : ") #파이썬3print t 2016. 3. 1. 이전 1 2 3 다음 반응형