Language/Python
# 결과값 * ** *** **** ***** -------- * ** *** **** ***** -------- ***** **** *** ** * -------- * ** *** **** ***** -------- ***** **** *** ** * -------- * *** ***** ******* ********* # 1 for i in range(5): for j in range(i + 1): print('*', end='') print() print('--------') for i in range(5): print('*'*(i+1)) print('--------') # 2 for i in range(5): print('*'*(5-i)) print('--------') # 3 for i in r..
Language/Python
i = 1 while i 5: break # else 출력x print(i) i += 1 else: # 반복문이 정상 완료(종료) 되었을 때 실행 print('i: ', i) print('------') for i in range(1,10): if i % 2 ==0: continue print(i) else: print('i', i, sep=':') # 결과값 1 2 3 4 5 ------ 1 3 5 7 9 i:9
Language/Python
subjects = ['java', 'javascript', 'python'] for i in subjects: # sequential한 객체들 print(i) else: print('다 재밌다') # 위에 반복이 정상 출력되고 나서 마지막에 출력 for j in range(1, 100): print(j, end=',') else: print('end!') print('구구단') for i in range(2,10): print(str(i)+'단') for j in range(1,10): #print('{}*{}={}'.format(i, j, i*j)) print(str(i)+'*'+str(j)+'='+str(i*j)) # range(start, end, step) for i in range(10, 0,..
Language/Python
# if else a = 1 if a == 1: print('a는 1 맞음 ') # space 2 or space 4 or tab -> if안의 명령문 else : print('a는 1 아님 ') # if ~ elif ~ else b = 2 if b == 1: print('b == 1') elif b == 2: print('b == 2') else: print('b !=1 & b!=2') # 결과값 a는 1 맞음 b == 2
Language/Python
# 결과값 hello, world! hello, python! ['hello,', 'world!\nhello,', 'python!'] ['hello,', 'world!\nhello, python!'] ['hello', '', 'world!', 'hello', '', 'python!'] ['1', '2', '3', '4'] 1+2+3+4 10 import re # split str01 = 'hello, world!\nhello, python!' print(str01) arr01 = str01.split(' ') print(arr01) arr02 = str01.split(' ', 1) print(arr02) arr03 = re.split(r'[\s]|[,]', str01) print(arr03) # joi..