목록Programming (97)
59doit
test_text 파일 이용하여 예외처리하기 print('\n유형별 예외처리') try: div = 1000 / 2.53 print('div=%5.2f' % (div)) div = 1000 / 0 # 1차 산술적예외 f = open('c:\\test/txt') # 2차 파일열기 num = int(input('숫자입력:')) # 3차 기타예외 print('num=', num) except ZeroDivisionError as e: # 다중예외처리 print('오류정보:', e) except FileNotFoundError as e: # 다중예외처리 print('오류정보:', e) except Exception as e: print('오류정보:', e) finally: print('finally 영역-항상 ..
findall 모듈추가 import re from re import findall 숫자찾기 & 문자열 찾기 from re import findall # 모듈추가 st1 = '123456 abc훈민정음 ABC_555_6 세종대왕' # 숫자 찾기 print(findall('1234',st1)) # ['1234'] print(findall('[0-9]',st1)) # ['1', '2', '3', '4', '5', '6', '5', '5', '5', '6'] print(findall('[0-9]{3}',st1)) # ['123', '456', '555'] print(findall('[0-9]{3,}',st1) # ['123456', '555'] print(findall('\\d{3,}',st1)) # ['123..
lst = [1,3,5] for i, c in enumerate(lst) : print('색인:',i, end=', ') print('내용:',c) # # 색인: 0, 내용: 1 # 색인: 1, 내용: 3 # 색인: 2, 내용: 5 dic = {'name':'jain','job':'teacher','age':'25'} for i, k in enumerate(dit) : print('순서:',i, end=', ') print('키:',k, end=', ') print('값:',dic[k]) # # 순서: 0, 키: name, 값: jain # 순서: 1, 키: job, 값: teacher # 순서: 2, 키: age, 값: 25 import 내장클래스 date 클래스 import datetime from ..
class calc_class : x=y=0 def __init__(self,a,b) : self.x = a self.y = b def plus(self): p = self.x + self.y return p def minus(self): m = self.x - self.y return m obj = calc_class(10,20) print('plus=',obj.plus()) print('minus=',obj.minus()) # # plus= 30 # minus= -10 class Car : cc = 0 door = 0 carType = 0 def __init__ (self,cc,door,carType) : self.cc = cc self.door = door self.carType = carType ..