Python(3)
-
Python @classmethod, @staticmethod 차이점
차이점은 부모 클래스에게서 상속 받을때 나타난다. 1. classmethod는 해당cls를 받아 값이 변경이되어 사용하고 2. staticmethod는 부모의 속성을 값을 그대로 받아 사용한다. 예시 class checkMethod(object): checkWord = '안녕하세요!' def __init__(self): self.greetings = '파이썬!' + self.checkWord @classmethod def classMode(cls): return cls() @staticmethod def staticMode(): return checkMethod() def printWord(self): print(self.greetings) class answer(checkMethod): checkWor..
2021.07.10 -
python 해당 값 찾기 in 연산자
data = ['짱구', '철수', '훈이', '유리', '맹구'] if '짱구' in data: print('짱구있어요!') if '신형만' in data: print('신형만 있어요!') elif '신형만' not in data: print('신형만 없어요!') #짱구있어요! #신형만 없어요! 해당값이 있는지 in 연사자를 이용해 확인이 가능하고, 값이 없는지 확인은 not 연산자를 이용해 확인 할 수 있다.
2021.07.09 -
SyntaxError: Non-ASCII character 에러 해결
파이썬을 실행할때 python 과 python3 명령어가 있다. python 명령어는 인코딩이 ASCLL이고 python3 명령어는 인코딩이 UTF-8이다 그래서 python 명령어를 사용 할 때 는 가장 첫 줄에 # -*- coding: utf-8 -*- 라고 적어 주고 실행해야 한다. 하지만 python3명령어는 utf-8로 인코딩을 하기때문에 정상 작동한다. 출처: https://korbillgates.tistory.com/97
2021.05.14