study with Q - 파이썬
-
91 - (파이썬) 패키지study with Q - 파이썬 2024. 9. 22. 20:27
#패키지: 모듈의 규모가 커졌을 때, 그 모듈을 나누는 방법 ㄱ) 모듈 : 관심사를 기반으로 함수와 변수를 나누는 것→ 프로그래밍 언어에 따라서 관심사를 묶는 방법이 매우 다양. 그 중 파이썬은 파일들을 폴더를 활용해서 묶는다. 방법1) 폴더 내부의 있는 모듈을 읽어들이는 방법 [1] school이라는 이름의 폴더를 만든다 [2] 내부에 StudentList를 배치해 볼 studentlist.py라는 파일과 클래스를 배치할 student.py라는 파일을 만든다. (일반적으로 클래스의 규모가 커지게 되면 클래스 각각을 파일로 만든다.) [3] student.py의 student 클래스 내부에는 수학 성적 입력 / 합계를 입력을 받는 코드를 작성한다.student.py>class Student: def _..
-
90 - (파이썬) 모듈 만들기study with Q - 파이썬 2024. 9. 19. 19:36
#모듈: 파일 또는 폴더를 활용해서 구성하게 된다 import 모듈이름→ 파이썬은 위와 같은 코드를 사용하게 되면 현재 실행하고 있는 파일이 있는 위치에서 "모듈이름"이라는 파일 또는 폴더가 있는지 확인한다. (모듈이름과 같은 이름의 파일을 만들어서 사용하면 오류가 발생한다.) 같은 이름의 파일/폴더가 없ㅇ면 환경 변수에 등록되어 있는 추가적인 위치에서 확인한다. eg) import sys라는 이름의 모듈이 현재 위치레 있는 곳이 아니다. > 환경 변수라는 곳에 설정되어 있는 위치에 있다.→ 시스템 모듈에 path라는 변수를 출력해보면 환경 변수에 어떠한 위치가 기록되어 있는지 확인 가능더보기import sysprint(sys.path)>>>['/home/runner/number2', '/nix/stor..
-
89 - (파이썬) 모듈 문제study with Q - 파이썬 2024. 9. 19. 18:27
1. 다음 중 math 모듈의 함수를 제대로 읽어 들이지 못하는 코드를 고르시오.① import math② import sin, cos, tan from math③ import math as m④ from math import *더보기import sin, cos, tan from math>>>File "/home/runner/number2/main.py", line 1 import sin, cos, tan from math ^^^^SyntaxError: invalid syntax2. 파이썬 문서를 보면서 모듈의 이름을 다섯 개 적고, 해당 모듈에 어떤 기능이 있는지 간단하게 적어보시오.더보기번호모듈 이름모듈 기능0wave 모듈wav 음악 형식과 관련된 처리..
-
88 - (파이썬) 기본 내장 모듈study with Q - 파이썬 2024. 9. 13. 18:51
#모듈 사용 흐름 - 기본적인 활용 방법1) 내가 무엇을 해야겠다는 인지2) 구글링3) 복사 사용4) 찾기 귀찮아질 때쯤 외우기 eg) 시간을 구하는 코드 라익댓 그럼 처음부터 구글링만 하면 된다하지 왜 why1) 그래도 뭐하는 코드인지 알아야 쓰지 않겠니why2) 아는 만큼 보인다 - 많이 봐야 어떤 기능이 있는지 인지할 수 있지 # random 모듈 uniform : 두 매개변수 사이에 있는 랜덤한 부동소수값을 출력randrange : 두 매개변수 사이에 있는 랜덤한 정수를 출력choice: 반복가능한 매개변수 중 요소 하나를 뽑아서 출력 print(random.uniform(100,190))print(random.randrange(1,45))print(random.choice([0, -1, -2, ..
-
87 - (파이썬) 모듈을 읽는 방법study with Q - 파이썬 2024. 9. 13. 15:56
그러니께 말여) 함수, 변수 등 어떠한 대상의 수가 많아짐에 따라 카테고리로 구분하기 위한 방법들이 나왔었다- #클래스: 객체라는 주어로 묶는 방법#모듈 : 관심사로 묶는 방법수학과 관련된 대상 → math 모듈랜덤 처리 관련 대상 → random 모듈시스템 관련 대상 → sys 모듈#모듈을 읽는 방법1) import 모듈로 읽는 방법→ "모듈"을 식별자로 읽는다.→ 모듈 내부에 있는 대상에 접근할 수 있다. (eg. 모듈. ~~~)예시)import mathprint(math.sin(1))print(math.cos(0))print(math.tan(0))print(math.ceil(13.1)) #올림print(math.floor(15.9)) #버림>>>0.84147098480789651.00.01415 2..
-
85 - (파이썬) 스택과 큐study with Q - 파이썬 2024. 9. 9. 19:56
# 스택:선입후출(First in Last out)(FILO) / 후입선출(Last in Fisst out)(LIFO) 구조를 갖는 자료 구조 박스에 책을 넣을때는 빨>파>초>노의 순으로 넣지만 다시 뺄 때는 노>초>파>빨의 순서로 빼게 된다. 푸시(push) : 스택에 자료를 넣는 행위팝(pop) : 스택에서 자료를 꺼내는 행위 #스택stack = Stack()stack.push("red") # ["red"]stack.push("blue") # ["red", "blue"]stack.push("green") # ["red", "blue", "green"]stack.push("yellow") # ["red", "blue", "green", "yellow"]stack.pop() # "yellow" ["..
-
83, 84 - (파이썬) 오버라이드와 super() 함수 / 상속과 컴포지션study with Q - 파이썬 2024. 9. 9. 19:26
83강 # 오버라이드 (oevrride): 재정의: 부모에 정의되어 있는 함수를 자식에서 다시 정의하는 것 #오버라이드class 부모: def 함수(self): print("부모의 함수")class 자식(부모): def 함수(self): print("자식의 함수")child = 자식()child.함수()>>>자식의 함수 파이썬에서는 먼저 자신의 클래스에 그 함수가 있는지를 확인하고 없다면 부모 클래스에 그 함수가 있는지 찾는다. # 자식 함수에서 부모 함수 호출하기class 부모: def 함수(self): print("부모의 함수")class 자식(부모): def 함수(self): super().함수() print("자식의 함수") super().함수()child ..
-
81 - 83 (파이썬) 강의 정리 포기, 코드 복붙study with Q - 파이썬 2024. 9. 1. 19:22
추가적인 요청1) 비교연산자를 사용하게 해주쇼2) + 연산자를 사용하게 해주쇼3) print() 함수를 일반적인 형태로 사용할 수 있게 해주쇼 물론 이런 요청은 터무니 없기에 무시해야 하지만... 실습을 위해 꾹 참고 해봅시다. 참고로) 특수 메소드메소드사용뜻__eq__self = otherequals__ne__self != othernot equals__gt__self > othergreater than__ge__self >= othergreater than or equal to__lt__self less than__le__self less than or equal to # 81강 코드 - 코드 복사class Student: def __init__(self, 이름, 국어, 영어, 수학, 과학)..