목록분류 전체보기 (90)
비전공개미 개발노트
In [3]: ''' OOP (Object Oriented Programing) 변수(저장), 함수(처리) 일반변수, tuple(변경불가능한 리스트), list, dictionary(자바의 map) list 접근 : index number 0 ~ length-1 -> 번호(숫자), dictionary 접근 : key(string) : value, OOP (Object Oriented Programing) class 변수(멤버) 초기화 함수 __init__ 함수(멤버) -> method ''' class Car: def __init__(self): print('Car __init__') car = Car() car.__init__() # 자바와는 다르게 따로 호출이 가능하다 Car __init__ Car ..
In [11]: honk = '빵빵' color = 'black' engine = '보통' honk = '빵빵' color = 'black' engine = '보통' mycar_honk = [] mycar_color = [] mycar_engine = [] mycar_honk.append('띠띠') mycar_color.append('노랑') mycar_engine.append('터보') mycar_honk.append('빵빵') mycar_color.append('블루') mycar_engine.append('250cc') # ---------------------------------------------- class Car: honk = '빵빵' color = '검정' engine = '보통' ca..
과제¶ In [ ]: ## 내 풀이 In [ ]: ''' 가위(0), 바위(1), 보(2) 게임 com : random user : 입력 판정 : 당신은 ?를 냈습니다 com은 ?를 냈습니다 당신이 이겼습니다 당신이 졌습니다 비겼습니다 ''' In [132]: import random # 입력 user = input('가위, 바위, 보 하나를 입력해주세요 > ') com = random.randint(0, 2) randcom = '' if com == 0: randcom = '가위' elif com == 1: randcom = '바위' elif com == 2: randcom = '보' # 비겼을경우 if randcom == user: output = '비겼습니다' # 이겼을경우 elif randcom ..
In [3]: import math In [4]: math.sin(1) Out[4]: 0.8414709848078965 In [5]: math.cos(1) Out[5]: 0.5403023058681398 In [7]: math.tan(1) Out[7]: 1.5574077246549023 In [8]: # 내림 math.floor(2.5) Out[8]: 2 In [9]: # 올림 math.ceil(2.5) Out[9]: 3 In [13]: # 반올림 round(3.5) Out[13]: 4 In [14]: round(1.3) Out[14]: 1 In [15]: round(3.141592, 2) # 소수점 2번째까지 Out[15]: 3.14 In [16]: round(3.141592, 3) # 소수점 3번째까..
file write¶ In [5]: file = open('test.txt', 'w') # 만들 파일명, w == write(쓰기) In [6]: file.write('안녕 파이썬 programing!!') file.close() # write로 기입한 후에 반드시 close로 닫아줘야됨 file read¶ In [15]: file_data = open('test.txt') In [16]: data = file_data.read() data Out[16]: '안녕 파이썬 programing!!' In [ ]: file_data.close() # 정석대로면 close()를 사용하지만 read에서는 필수는 아님(오류x) In [18]: with open('test.txt', 'r') as f: # close..
In [5]: ''' 함수 function, method # 입력값 parameter, 매개변수, 인수, 인자 #출력값 return 값 define의 약자(선언) def 함수명(매개변수1, ...) 처리 return 값 ''' # function(함수)의 선언(정의) def funcName() : print('funcName() 호출') funcName() # function의 호출 funcName() 호출 In [8]: def funcOne(n, s) : # n, s 매개변수, 가(상)인수 for i in range(n) : print(s) # n의 값의 range를 돌리고 s값을 n의 값만큼 반복 출력한다 funcOne(10, 'hi good day') # 10, 'hi good day' argume..
lambda : 줄여쓰기, 간단하게 기입¶ In [1]: mylist = list(range(10)) mylist Out[1]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] In [2]: for i in mylist : print(i) 0 1 2 3 4 5 6 7 8 9 In [5]: [i for i in mylist] # for문을 한줄로 처리할 수 있다 Out[5]: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] In [48]: list_a = [0, 1, 2, 3, 4] list_b = [5, 6, 7] # 2차원 배열 list_c = [list(range(5)),[5, 6, 7]] #== list_c = [list_a, list_b] list_c list_c[0] Out[48]..
In [4]: ''' 조건 : if, elif 순환 : for, while, do while 제어 : continue, break if 조건 [or, and 조건1] : -> 논리 조건이 True일 경우의 처리 ''' number = 3 if number > 0 : print('number는 양수입니다.') ## if 조건문 들여쓰기로 구분 number는 양수입니다. In [6]: if number ') # number = int(nu..