목록Programming/Python (20)
Allen's 데이터 맛집
for element in some_list: if not elemet: pass for element in some_list: if not elemet: continue pass는 단순히 실행할 코드가 없다는 것을 의미. continue는 다음 순번의 loop를 돌도록 강제하는 것을 의미. pass 와는 다르게 continue는 바로 다음 순번의 loop를 돈다.
상속과 다중 상속은 객체 지향 프로그래밍에서 중요한 개념입니다. 파이썬은 다중 상속을 지원하며, 여러 개의 클래스로부터 상속받을 수 있습니다. 1. 상속(Inheritance): 상속은 한 클래스가 다른 클래스의 속성과 메소드를 물려받는 것을 의미합니다. # 부모 클래스 정의 class Animal: def speak(self): print("동물이 소리를 낸다.") # 자식 클래스 정의 class Dog(Animal): def bark(self): print("멍멍!") # 인스턴스 생성 및 메소드 호출 dog = Dog() dog.speak() # 출력 결과: 동물이 소리를 낸다. dog.bark() # 출력 결과: 멍멍! 이 예제에서 Dog 클래스는 Animal 클래스를 상속받았기 때문에 speak..
클래스 파이썬에서 클래스는 객체 지향 프로그래밍 (OOP)의 기본 요소 중 하나입니다. 클래스는 속성(attribute)과 메서드(method)를 포함하는 데이터 구조를 정의합니다. 속성은 클래스의 상태를 나타내고, 메서드는 클래스의 동작을 정의합니다. class AttackUnit : def __init__(self,name, hp, damage): self.name = name self.hp = hp self.damage = damage def attack(self, location): print('{0} : {1} 방향으로 적군을 공격 합니다. [공격력 {2}]'\ .format(self.name,location, self.damage )) def damaged(self, damage): print..
이번 포스팅에서는 파일 입출력에 대해서 알아보겠습니다. score_file 이란 txt파일을 만들어서 넣기 score_file = open("score.txt","w",encoding="utf8") print('수학 : 0', file = score_file) print('영어 : 50', file = score_file) score_file.close() 한글 문자를 입력할 때는 encoding-"utf8" 넣어주기. 파일을 열었으면 항상 close() 해주기. 'w'는 쓰기(write) 용도란 뜻. 있던 파일에 추가 입력 a 는 append의 약자로, 원래 있던 것에 추가. score_file = open("score.txt", "a", encoding = "utf8") score_file.write..