본문 바로가기

전체 글141

22. Variable type annotation 1. Variable type annotation Python variable type annotations are a feature that allows user to specify the type of data that a variable will store. This can greatly improve the readability of user code and help user catch type errors early in the development process. Improved readability: By specifying the type of a variable, you make it easier for anyone reading your code to understand what kin.. 2024. 3. 21.
22. 변수 타입 어노테이션 1. 변수 타입 어노테이션 파이썬 변수 타입 어노테이션은 변수가 저장할 데이터의 타입을 명시하는 기능입니다. 이는 코드의 가독성을 높이고, 개발 단계에서 타입 오류를 사전에 잡아내는 데 큰 도움을 줍니다. 가독성 향상: 변수의 타입을 명시함으로써 코드를 읽는 사람이 변수가 어떤 값을 저장하는지 쉽게 이해할 수 있습니다. 정적 타입 검사: mypy와 같은 정적 타입 검사 도구를 사용하여 코드를 실행하기 전에 타입 오류를 발견하고 수정할 수 있습니다. 코드 유지 관리: 코드의 타입을 명시함으로써 코드를 더 쉽게 이해하고 유지 관리할 수 있습니다. 2. 기본 타입 어노테이션 3. 리스트, 튜플, 딕셔너리, 세트 컬렉션 타입에 대한 어노테이션은 조금 더 복잡합니다. 이를 위해 List, Tuple, Dict, .. 2024. 3. 21.
21. Creating a vocabulary book using file input and output Question Create an English vocabulary program that satisfies the following conditions: 1.Register, 2. Print, 3.Save, 4. Load, 5. Off If 1 is selected: Enter the word: apple Enter the meaning: 사과 (apple in Korean) Enter the level: 1 Registered If 2 is selected: apple: 사과 (Level 1) If 3 is selected: Saved successfully. (Saved to a file, words.txt) If 4 is selected: Loaded successfully. (Read from .. 2024. 3. 21.
21. 파일 입출력을 이용한 단어장 만들기 문제 아래 조건을 만족하는 영어 단어장을 만들어보자 1.등록하기, 2. 출력하기, 3.저장하기, 4. 불러오기, 5. 종료하기 1을 선택했을 경우 단어를 입력하세요: apple 뜻을 입력하세요: 사과 레벨을 입력하세요: 1 등록되었습니다. 2를 선택했을 경우 apple : 사과 (레벨 1) 3을 선택했을 경우 저장되었습니다. (파일에 저장, words. txt) 4를 선택했을 경우 불러왔습니다라는 메세지가 뜸(파일에서 읽어옴, word.txt에서) 5를 선택했을 경우 프로그램을 종료합니다. 1~5까지의 숫자가 아닌 경우 *다시 입력하세요! 단, 프로그램은 클래스로 설계하도록 함 답 결과 2024. 3. 21.
20. File I/O in Python 1. File Open 파이썬에서 파일을 열려면 open() 함수를 사용합니다. open() 함수는 두 가지 인수를 받습니다. 2. File Write There are two watys to write coontent to a file write(): Writing a string to the file writelines(): Writehs a list of strings to the file 3. Using the With statement Python's with statement allows user to open a file, perform operations on it, and automatically close the file afterwards 4. File Read There are se.. 2024. 3. 20.
20. 파일 입출력 1. 파일 열기 파이썬에서 파일을 열려면 open() 함수를 사용합니다. open() 함수는 두 가지 인수를 받습니다. 2. 파일 쓰기 파일에 내용을 쓰는 방법은 두 가지입니다. write(): 문자열을 파일에 쓴다. writelines(): 문자열 리스트를 파일에 쓴다. 3. with 문 사용하기 파이썬의 with 문을 사용하면 파일을 열고 작업을 수행한 후 자동으로 파일을 닫을 수 있습니다. 4. 파일 읽기 파일에 저장된 내용을 읽는 방법은 여러 가지입니다 read(): 파일의 모든 내용을 문자열로 반환 readline(): 파일의 한 줄을 문자열로 반환 readlines(): 파일의 모든 줄을 리스트로 반환 5. 예외 처리와 함께 사용하기 파일 입출력 중에는 여러 가지 오류가 발생할 수 있습니다 (.. 2024. 3. 20.