목록Python/기초 (16)
기루 기룩 기록

1. 대문자/소문자 변환 함수 설명 사용법 upper() 소문자를 모두 대문자로 변환 문자열.upper() lower() 대문자를 모두 소문자로 변환 문자열.lower() swapcase() 대문자/소문자를 상호 변환 문자열.swapcase() title() 각 단어의 앞글자만 대문자로 변환 문자열.title() # 대문자/소문자 변환 python = "Python is EASY" print(python.upper()) print(python.lower()) print(python.swapcase()) print(python.title()) 2. 공백 제거, 추가, 변경 함수 설명 사용법 strip() 앞/뒤쪽 공백 제거 문자열.strip() rstrip() 뒤쪽 공백 제거 문자열.rstrip() lst..

리스트 조작 함수 함수 설명 사용법 append( ) 리스트의 마지막에 값을 추가한다 list.append(값) pop( ) 리스트의 마지막 값을 추출후 제거한다 list.pop( ) sort( ) 리스트의 항목을 정렬한다 list.sort( ) reverse( ) 리스트의 항복을 역순으로 만든다 list.reverse( ) index( ) 값을 찾아 위치를 반환한다 list.index(값) insert( ) 지정된 위치에 값을 삽입한다 list.insert(위치, 값) remove( ) 리스트에서 지정한 값을 제거, 여러개일 경우 천 번째 값만 제거한다 list.remove(값) extend() 리스트 뒤에 리스트를 추가한다 list.extend(리스트) count( ) 리스트에서 찾을 값의 개수를 센..

open("파일 위치", "r" or "w" 열기모드 , encoding = "파일 형식") 을 통해 입출력을 수행 할 수있습니다 -열기모드 "r"의 경우 파일을 읽을때 사용합니다. "w"의 경우 파일을 작성할때 사용합니다. 생략할 경우 "r"과 동일합니다 "r+" 읽기/쓰기 겸용모드 "a" 쓰기모드, 기존에 파일이 있으면 이어서 작성. append의 약자 "t" 텍스트 모드, 텍스트 파일을 처리, 기본값 "b" 바이너리 모드, 바이너리 파일(=이진 파일)을 처리 # 파일 출력 inFp = None inStr = "" inFp = open("D:/python/data.txt", "r", encoding = "utf-8") inStr = inFp.readline() print(inStr, end="") i..

모듈(Module)은 함수들의 집합이라 생각할 수 있다. 함수들을 A.py에 작성하는 것이 아닌 module1.py에 작성하여 A.py뿐 아니라 B.py, C.py 등 여러 파이썬 파일에서 재사용할 수 있도록 할 수 있습니다. ## 파일명: module1.py # 모듈 파일 def func1(): print("모듈의 func1 함수") def func2(): print("모듈의 func2 함수") # main 파일 import module1 module1.func1() module2.func2()

파이썬에서 함수를 정으하기 위해선 def를 사용합니다. def 함수이름(인스턴스): 실행 내용1 실행 내용2 return 반환 내용 예를 보고 확인하겠습니다. # 함수 정의하기 def plus(a, b): result = a+b return result def minus(a, b): result = a-b return result value = plus(10, 20) print(value) print(plus(10, 20)) value = minus(10, 20) print(value) print(minus(10, 20))

파이썬에서 출력문은 print() 함수를 사용하며, 두 가지 옵션을 설정할 수 있습니다.- sep=" " 이 옵션은 출력할 값들 사이에 삽입할 문자를 지정합니다. 기본값은 공백(" ")이며, 원하는 다른 문자를 넣어 출력 형식을 변경할 수 있습니다.- end=" "이 옵션은 print() 함수가 출력된 후 추가할 문자를 지정합니다.기본값은 개행 문자(\n)로, 출력이 끝난 뒤 자동으로 줄바꿈이 이루어집니다.이 값을 수정하면 개행 대신 원하는 문자나 공백을 넣을 수 있습니다. 먼저, 별도의 옵션 없이 print() 함수만 사용하여 출력을 할 경우입니다.이 경우 출력 값들 사이에는 기본적으로 공백(" ")이 들어가고, 출력이 완료된 후에는 자동으로 줄바꿈이 이루어집니다.print("1-1칸","1-2칸","..